Python 3.x 如何遍历列表以在dataframe中查找值

Python 3.x 如何遍历列表以在dataframe中查找值,python-3.x,pandas,Python 3.x,Pandas,我试图遍历SQLite3 sql\u min中的时间戳列表,以在列df['Timestamp']中找到匹配的值,然后返回相应的行号df['date\u index'] 我希望返回行号的整数,但得到 系列[],名称:日期索引,数据类型:int32或 ValueError:长度必须匹配以比较如果你考虑时间戳为字符串,你可以尝试如下: for item in sql_min: indx = df.date_index[df.index[df.timestamp.str.contains(ite

我试图遍历SQLite3 sql\u min中的时间戳列表,以在列df['Timestamp']中找到匹配的值,然后返回相应的行号df['date\u index']

我希望返回行号的整数,但得到 系列[],名称:日期索引,数据类型:int32或
ValueError:长度必须匹配以比较

如果你考虑时间戳为字符串,你可以尝试如下:

for item in sql_min:
    indx = df.date_index[df.index[df.timestamp.str.contains(item)]]
    print(indx.to_string(index=True))
for item in sql_min:
    indx = df.date_index[df.index[df.timestamp.str.contains(item)]]
    print(indx.to_string(index=True))