[英]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.