Im trying to create an excel file with pandas for a database I have generated.
I have tried both:
import pandas as pd # write database to excel df = pd.DataFrame(database) # Create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter('fifa19.xlsx', engine='xlsxwriter') # Convert the dataframe to an XlsxWriter Excel object. df.to_excel(writer, sheet_name='Sheet1') # Close the Pandas Excel writer and output the Excel file. writer.save()
as well as:
import pandas as pd df = pd.DataFrame(database).T df.to_excel('database.xls')
However, none of the options generate an excel file. Database is a dictionary.
From the pandas document Notes itself:
If passing an existing ExcelWriter object, then the sheet will be added to the existing workbook. This can be used to save different DataFrames to one workbook:
>>> writer = pd.ExcelWriter('output.xlsx') # writer = pd.ExcelWriter('/path_to_save/output.xlsx') >>> df1.to_excel(writer,'Sheet1') >>> df2.to_excel(writer,'Sheet2') >>> writer.save()
For compatibility with to_csv, to_excel serializes lists and dicts to strings before writing.