I imported an excel file, performed a Group By on a certain column in a dataframe, now I want to export that output (sort of pivot) back in the excel workbook in another sheet, is it possible to do that?
I imported an excel file, performed a Group By on a certain column in a dataframe, now I want to export that output (sort of pivot) back in the excel workbook in another sheet, is it possible to do that?
By import you mean you can write back to excel, and of course you can by using the ExcelWriter in pandas.
You can do it like so:
import pandas as pd
# Read and manipulate you DataFrame
...Lines of Codes...
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('your_file_name.xlsx', engine='xlsxwriter')
# Write dataframe to new sheet
df.to_excel(writer, sheet_name='AnotherSheet')
# Close the Pandas Excel writer and output the Excel file.
writer.save()
Since this can be done in python, it can surely be done in jupyter-notebook
Short method is if your output is in DataFrame, you can use this function to export output as excel. suppose output is in variable name out. Then do that:
out.to_excel(r'Path\File Name.xlsx', sheet_name='Your sheet name', index = False)
How about this?
data.to_excel( excel_writer, sheet_name='Sheet1', \*\*kwargs )
Documentation: https://www.geeksforgeeks.org/dataframe-to_excel-method-in-pandas/