How to save Pandas df.info()
function output to variable or data frame?
I tried using buffer value but it is not saving output neatly.
Code:
import io
buffer = io.StringIO()
df.info(buf=buffer)
s = buffer.getvalue()
with open("df_info.txt", "w",
encoding="utf-8") as f:
f.write(s)
Result:
Sample output:
column non-null count dtype
We should get the output like in result in above 3 columns.
How can I do this?