Member-only story
How To Export .XLSX / .CSV Files In Python
Python is a beautiful language, and exporting data through Python is a very strong asset for this language, so let’s see how to export specific data sets out of Python in different data types!
Exporting .XLSX Files
There are 2 main ways to export your Python, the first being if you’re only exporting 1 sheet, the second being if you’re exporting multiple sheets. To export 1 sheet, assuming the dataframe name is df, we use the following line of code:
df.to_excel(r'The Path to where we export the excel file Name.xlsx', index = False)#WITH EXPORTED NAME COMPLETE
df.to_excel(r'/Users/users/Desktop/DataFrame.xlsx', index = False)
The second way to export it with multiple sheets would be this way:
df.to_excel(r'Path to store the exported excel file\File Name.xlsx', sheet_name='Your sheet name', index = False)#WITH EXPORTED NAME
df.to_excel(r'/Users/users/Desktop/DataFrame.xlsx', sheet_name='Your sheet name', index = False)
Exporting .CSV Files
Assuming the data frame is named “df”, to export a .CSV file within Python, the easiest way to do this is:
df.to_csv(r'Path where you want to store the exported CSV file\File Name.csv', index = False)#WITH THE SPECIFIED FILE DIRECTORY
df.to_csv(r'/Users/users/Desktop/DataFrame.xlsx', index = False)
Make sure to change the directories for your specific data frame.
That’s pretty much it, enjoy exporting your data from Python!