How do you export a Pandas DataFrame to an Excel file? It’s very easy to do.
I will test it by creating a project in Jupyter Notebook with Anaconda Navigator.
# import pandas import pandas as pd # manually create a DataFrame import pandas as pd # import the pandas library into Python data = {'firstname': ['Bob', 'Sally', 'Suzie', 'Rowan'], 'amount': [12, 67, 33, 41]} df = pd.DataFrame(data) df
Here is what Jupyter shows.
# specify the name of the file file_name = 'D:\Test\People.xlsx' # saving the excel file df.to_excel(file_name) print('DataFrame is written to Excel File successfully.')
It’s possible to get errors. For example, if the folder Test does not exist, the Excel file will not be written.
For more information try GeeksForGeeks Exporting a Pandas DataFrame to an Excel file.