繁体   English   中英

类型错误:列表索引必须是整数或切片,而不是 str

[英]Type Error: list indices must be integers or slices, not str

我的代码有什么问题?继续获取

TypeError: list indices must be integers or slices, not str"*
ata2 = [{'one': 1, 'two': 2}, {'one': 5, 'two': 10, 'three': 20}]


pd.DataFrame(ata2,index=['a','b'],columns=['one','two','three'])

ata2['four']=ata2['one']* ata2['two']

如果您尝试进行列乘,则需要将ata2设置为pd.DataFrame ,因此,您需要: ata2 = pd.DataFrame(ata2,index=['a','b'],columns=['one','two','three'])

否则, ata2仍然是list ,而不是DataFrame - 您只能使用int的索引访问列表!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM