有没有办法将 Pandas 数据框信息——df.info() 导出到一个 excel 文件中? [英] Is there a way to export pandas dataframe info -- df.info() into an excel file?

查看:39
本文介绍了有没有办法将 Pandas 数据框信息——df.info() 导出到一个 excel 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地有一个 .csv 文件.我正在用熊猫阅读文件.我想将 df.info() 结果移动到 excel 中.看起来 df.info().to_excel 不起作用,因为它不受支持.有没有办法做到这一点?

I have a .csv file locally. I am reading the file with pandas. I want to move the df.info() result into an excel. Looks like df.info().to_excel does not work as it is not supported. Is there any way to do this?

我试过 df.info().to_excel

I tried df.info().to_excel

import pandas as pd
from openpyxl.workbook import Workbook
pd.read_csv("file.csv",sep='|', error_bad_lines=False)
writer = pd.ExcelWriter('output.xlsx')
df.info()
df.info().to_excel(writer,sheet_name='info')

我想在 Excel 的单个选项卡中显示数据框信息输出.

I want to show the dataframe info output in a single tab of the excel.

推荐答案

对我来说,最简单的方法是在数据帧中获取相同的信息,但要分开获取:

The easiest way for me is to get the same information in dataframes, but separately:

df_datatypes = pd.DataFrame(df.dtypes)
df_null_count = df.count()

然后像往常一样写到 excel.

Then write to excel as usual.

这篇关于有没有办法将 Pandas 数据框信息——df.info() 导出到一个 excel 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆