[英]What is the solution to this type error :list indices must be integers or slices, not 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.