是否可以将Jupyter notebook的输出导出到Excel?



我导入了一个excel文件,在数据框的某一列上执行了分组,现在我想在另一个工作表的excel工作簿中导出该输出(某种pivot),是否有可能这样做?

通过import,你的意思是你可以写回excel,当然你可以使用pandas中的ExcelWriter。
你可以这样做:

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()

既然这可以在python中完成,它当然可以在jupyter-notebook

中完成

短方法如果输出是DataFrame格式,则可以使用此函数将输出导出为excel格式。假设输出在变量名为out中。然后这样做:

out.to_excel(r'PathFile Name.xlsx', sheet_name='Your sheet name', index = False)

这个怎么样?

data.to_excel( excel_writer, sheet_name='Sheet1', **kwargs )

文档:https://www.geeksforgeeks.org/dataframe-to_excel-method-in-pandas/

最新更新