是否可以将Jupyter笔记本的输出导出到Excel?

2024-05-29 05:51:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我导入了一个excel文件,对数据框中的某一列执行了分组操作,现在我想将该输出(类似于枢轴)导出回另一个工作表中的excel工作簿中,是否可以这样做


Tags: 文件数据excel枢轴
3条回答

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

out.to_excel(r'Path\File 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/

通过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笔记本中完成

相关问题 更多 >

    热门问题