“列表索引必须是整数或切片,而不是DataFrame”错误

时间:2019-08-18 08:16:57

标签: python pandas loops

我有两个数据框,它们附加在列表中。

one=pd.DataFrame({"col1":[2,3,4,5,3],"col2":[9,4,3,4,5]})
two=pd.DataFrame({"col1":[5,8,1,3,3],"col2":[5,2,9,1,5]})

mylist=[]
for i in [one,two]:
    mylist.append(i)

我运行mylist[1]["col1"]

我有输出

    0    5
    1    8
    2    1
    3    3
    4    3

但是,当我执行如下循环时:

for table in mylist:
    print(mylist[table]["col1"])

我收到以下错误:

"list indices must be integers or slices, not DataFrame"

有人可以帮助我以正确的方式创建循环吗?谢谢

0 个答案:

没有答案