我是 Python 和 Pandas 的新手。
我想在我的 pandas 数据框中找到某个值的索引(比方说 security_id
),因为那是列的开始位置。
(列上方有未知数量的行和不相关的数据,左侧还有许多空“列”。)
据我所知,isin方法只返回一个关于值是否存在的 bool 值,而不是它的索引。
如何找到这个值的索引?
最佳答案
获取所有列中匹配搜索词的行的索引
search = 'security_id'
df.loc[df.isin([search]).any(axis=1)].index.tolist()
在所有列中为匹配搜索词过滤的行
search = 'search term'
df.loc[df.isin([search]).any(axis=1)]
关于python - Pandas - 在 DataFrame 中的任何位置查找值索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42386629/