首页 > 解决方案 > 在 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)时,输出只是输出中的每个单词,然后是一个很难阅读/使用的新行。我的目标是能够更好地理解数据框中的列,并能够按类型对它们进行排序。

标签: pythonpandasdataframe

解决方案


您需要打开一个文件,然后将文件句柄传递给df.info

with open('info_output.txt','w') as file_out:
  df.info(buf=file_out)

推荐阅读