Python pandas :数据帧读取行(readlines)

Python pandas : dataframe read rows (readlines)

我有一个由 pandas 生成的数据框,例如:

d = {'one':[1,1],'two':[2,2], 'three':[3,3]}
i = ['a','b','c']
df = pd.DataFrame(data = d, index = i)
df

        one two three

  a     1   2    3

  b     1   2    3

  c     1   2    3

我现在需要用逗号分隔读取每一行,我不想保存 to_csv 然后再打开它,有什么好的建议吗?

我已经习惯了 python:

for line in df.readlines():
    print line

但是我现在不知道怎么联系我的想法,非常感谢!

我不知道你为什么不想保存并重新打开,但试试这个:

df = df.astype(str)
separators = pd.DataFrame(', ', df.index, df.columns[:-1])
separators[df.columns[-1]] = '\n'
print (df + separators).sum(axis=1).sum()

1, 3, 2
1, 3, 2
1, 3, 2