+2 votes
in Programming Languages by (77.8k points)
How can I create an excel file using pandas? Can I get a python code for this?

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

The Python code to create an excel file using pandas library is as follows:

import pandas as pd

# Create a Pandas dataframe from the data.
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('test.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()

The output file should look like this:

excel file using pandas

Reference


...