Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store (df.info) method output in DataFrame or CSV

I have a giant Dataframe(df) that's dimensions are (42,--- x 135). I'm running a df.info on it, but the output is unreadable. I'm wondering if there is any way to dump it in a Dataframe or CSV? I think it has something to do with:

```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."

But when i add a (buf = buffer) the output is just each word in the output then a new line which is very hard to read/work with. My goal is to be-able to better understand what columns are in the dataframe and to be able to sort them by type.

like image 982
Adam Safi Avatar asked Mar 12 '26 22:03

Adam Safi


1 Answers

You need to open a file then pass the file handle to df.info:

with open('info_output.txt','w') as file_out:
  df.info(buf=file_out)
like image 99
mechanical_meat Avatar answered Mar 15 '26 10:03

mechanical_meat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!