python - 在 DataFrame 或 CSV 中存储(df.info)方法输出
问题描述
我有一个巨大的 Dataframe(df),其尺寸为 (42,--- x 135)。我在上面运行 df.info,但输出不可读。我想知道是否有任何方法可以将其转储到 Dataframe 或 CSV 中?我认为这与以下方面有关:
```buf : writable buffer, defaults to sys.stdout
```Where to send the output. By default, the output is printed to sys.stdout. Pass a writable buffer
```if you need to further process the output."
但是当我添加一个(buf = buffer)时,输出只是输出中的每个单词,然后是一个很难阅读/使用的新行。我的目标是能够更好地理解数据框中的列,并能够按类型对它们进行排序。
解决方案
您需要打开一个文件,然后将文件句柄传递给df.info
:
with open('info_output.txt','w') as file_out:
df.info(buf=file_out)
推荐阅读
- html - 背景图像未使用 CSS 显示
- powerbi - 我们如何从 Web 发布的报告中导出数据
- python - 用 scapy 和正则表达式嗅探网络流量?
- html - 黑色字体并不是真正的“黑色”
- python - 后视模式无效
- json - 使用 stringify 时将未分配的 JSON 属性发送到服务器,即保留属性名称是否属性值为空/null
- inno-setup - 我可以创建不需要管理员权限的 Inno 更新程序吗?
- ionic-framework - Mapbox 地图未填充离子含量全屏
- javascript - v-for 将我的列表呈现在一行多列而不是一列多行
- swift - NSAttributedString to HTML to NSAttributedString 颜色退化