我想我在尝试保存包含一堆 Pandas 数据帧的 Pandas 系列时搞砸了。事实证明,每个 DataFrame 都像我调用df.to_string()它们一样被保存。
从我目前的观察来看,我的字符串在某些地方有额外的间距,\当 DataFrame 有太多列无法在同一行上显示时,我的字符串也会有额外的间距。
这是一个“更合适的数据帧:
df = pd.DataFrame(columns=["really long name that goes on for a while", "another really long string", "c"]*6,
data=[["some really long data",2,3]*6,[4,5,6]*6,[7,8,9]*6])
我拥有并希望变成 DataFrame 的字符串如下所示:
# str(df)
' really long name that goes on for a while another really long string c \\\n0 some really long data 2 3 \n1 4 5 6 \n2 7 8 9 \n\n really long name that goes on for a while another really long string c \\\n0 some really long data 2 3 \n1 4 5 6 \n2 7 8 9 \n\n really long name that goes on for a while another really long string c \\\n0 some really long data 2 3 \n1 4 5 6 \n2 7 8 9 \n\n really long name that goes on for a while another really long string c \\\n0 some really long data 2 3 \n1 4 5 6 \n2 7 8 9 \n\n really long name that goes on for a while another really long string c \\\n0 some really long data 2 3 \n1
我如何将这样的字符串还原回 DataFrame?
谢谢
守着一只汪
相关分类