【发布时间】:2019-03-15 02:33:48
【问题描述】:
test 是一个转换为字符串的 pandas 数据框。
strtest = (test.to_string())
print strtest
转换为字符串后,我有以下输出:
This is the first test file 98128612.12
This is the second test file 31236164.15
我正在尝试将字符串的每一行放入一个列表并打印出来,如下所示:
['This is the first test file','98128612.12']
['This is the second test file','31236164.15']
这是我尝试在列表中生成上述输出时的代码:
testlist = []
for row in strtest.iterrows():
index, data = row
testlist.append(data.tolist())
print testlist
但是当我运行它时,我遇到了这个错误我该如何解决这个问题:
for row in strtest.iterrows():
AttributeError: 'unicode' object has no attribute 'iterrows'
【问题讨论】:
标签: python-2.7 pandas list for-loop itertools