rob
rob

Reputation: 317

Export Calculations in Pandas to Produce Excel Table

I can't seem to find an answer to this... I've done multiple calculations in Pandas and want to export the results to Excel. I don't want to produce charts or export the dataframes, just the calculation results in the form of a table of 5 columns and 5 rows (plus headers).

What's the best way of doing this?

Upvotes: 0

Views: 234

Answers (2)

Bhavani Ravi
Bhavani Ravi

Reputation: 2291

Have you tried using pandas.to_excel method? You can construct a dataframe of your choice with the 5 rows, columns, and headers and then export it to an excel file.

df = df[["col1", "col2", "col3"]]
df.to_excel("export.xlsx", sheet_name='new_sheet') 

Upvotes: 1

geobreze
geobreze

Reputation: 2422

You can use to_excel function (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html).

Also, you can export your DataFrame to CSV (Microsoft Excel supports this file type) using to_csv (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html#pandas.DataFrame.to_csv).

Upvotes: 1

Related Questions