how to save output from dataframe info to file a excel or text file

爷,独闯天下 提交于 2019-12-18 09:34:18

问题


How can I write

df.info() to file?

I would like to include this in a sheet of the excel file where I write my df to using df.to_excel.

According to the docs (pandas.DataFrame.info) it returns a

buf : writable buffer, defaults to sys.stdout


回答1:


I would try the following:

f = open('df.info', 'w+')

df.info(buf=f)

f.close()


来源:https://stackoverflow.com/questions/35436331/how-to-save-output-from-dataframe-info-to-file-a-excel-or-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!