[英]Python - Error when saving output of Dataframe to excel
I am trying to print out shape of a Dataframe to a excel file. 我试图将Dataframe的形状打印到excel文件。
Given below is what I have achieved thus far: 以下是我迄今取得的成就:
file_shape = df.shape[0] <<-- This saves the count of rows to a variable
writer = pd.ExcelWriter(output, engine='xlsxwriter')
file_shape.to_excel(writer, startrow=0, merge_cells=False, sheet_name="Summary", index=False)
The above throws an error 以上引发了错误
AttributeError: 'int' object has no attribute 'to_excel'
Try the following: 请尝试以下方法:
file_shape = df.shape[0] # <<-- This saves the count of rows to a variable
df['file_shape'] = file_shape
writer = pd.ExcelWriter(output, engine='xlsxwriter')
df.to_excel(writer, startrow=0, merge_cells=False, sheet_name="Summary", index=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.