print small DataFrame to STDOUT and read it back into dataframe
Luca
please_no at spam.it
Sat Apr 4 19:00:23 EDT 2020
possibly a stupid question. Let's say I have a (small) dataframe:
import pandas as pd
dframe = pd.DataFrame({'A': ['a0','a1','a2','a3'],
'B': ['b0','b1','b2','b3'],
'C': ['c0','c1','c2','c3'],
'D': ['d0','d1','d2','d3']}, index=[0,1,2,3])
Is there a way that I can ask this dataframe to "print itself" in a way
that I can copy that output and easily rebuild the original dataframe
with index, columns and all?
dframe.to_string
gives:
<bound method DataFrame.to_string of A B C D
0 a0 b0 c0 d0
1 a1 b1 c1 d1
2 a2 b2 c2 d2
3 a3 b3 c3 d3>
Can I evaluate this string to obtain a new dataframe like the one that
generated it?
Thanks
More information about the Python-list
mailing list