简体   繁体   English

获取 TypeError:列表索引必须是整数或切片,而不是 str

[英]Getting a TypeError: list indices must be integers or slices, not str

I´m pretty new at python, cant seem to get this code to work, getting a "TypeError: list indices must be integers or slices, not str," --help please !我是 python 的新手,似乎无法让这段代码工作,得到一个“TypeError:列表索引必须是整数或切片,而不是 str,”——请帮助! Thanks a ton万分感谢

import pandas as pd 
from glob import glob
filenames = glob('abc*.xls')
df3 =[pd.read_excel(f) for f in filenames]
df4 = df3[df3['Unnamed: 11'].str.contains("tele", na=False)]

Here df3 is list of DataFrames , because created by list comprehension.这里df3list of DataFrames ,因为是由列表理解创建的。

So you can join all DataFrames together if possible:因此,如果可能,您可以将所有 DataFrame 连接在一起:

df3 =[pd.read_excel(f) for f in filenames]
df33 = pd.concat(df3, ignore_index=True)
df4 = df33[df33['Unnamed: 11'].str.contains("tele", na=False)]

Another idea is processing each DataFrame separately:另一个想法是分别处理每个 DataFrame :

for df in df3:
    df4 = df3[df3['Unnamed: 11'].str.contains("tele", na=False)]
    ...
    ...

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

相关问题 检索ID并获取TypeError:列表索引必须是整数或切片,而不是str - Crawling IDs and getting TypeError: list indices must be integers or slices, not str “TypeError:list indices必须是整数或切片,而不是str” - “TypeError: list indices must be integers or slices, not str” TypeError:列表索引必须是整数或切片,而不是 str - TypeError: List indices must be integers or slices and not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str “TypeError:列表索引必须是整数或切片,而不是 str” - "TypeError: list indices must be integers or slices, not str" TypeError:列表索引必须是整数或切片而不是 str - TypeError: list indices must be integers or slices not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str 获取列表索引必须是整数或切片,而不是str - Getting list indices must be integers or slices, not str Python3-TypeError:列表索引必须是整数或切片,而不是str-List - Python3 - TypeError: list indices must be integers or slices, not str - List 获取类型错误:字节索引必须是整数或切片,而不是 str - Getting TypeError: byte indices must be integers or slices, not str
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM