pandas -在DataFrame中的任何位置查找值的索引 [英] Pandas - find index of value anywhere in DataFrame
本文介绍了 pandas -在DataFrame中的任何位置查找值的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Python&的新手.熊猫
I'm new to Python & Pandas.
我想在我的pandas数据框中找到某个值的索引(比如说security_id
),因为那是列的起点.
(在列上方,有不相关数据的行数未知,在左侧还有空的列"数.)
I want to find the index of a certain value (let's say security_id
) in my pandas dataframe, because that is where the columns start.
(There is an unknown number of rows with irrelevant data above the columns, as well as a number of empty 'columns' on the left side.)
据我所见, isin 方法仅返回值是否存在的布尔值,而不是其索引.
As far as I see, the isin method only returns a boolean on whether the value exists, not its index.
如何找到该值的索引?
推荐答案
假设您的DataFrame如下所示:
Supposing that your DataFrame looks like the following :
0 1 2 3 4
0 a er tfr sdf 34
1 rt tyh fgd thy rer
2 1 2 3 4 5
3 6 7 8 9 10
4 dsf wew security_id name age
5 dfs bgbf 121 jason 34
6 dddp gpot 5754 mike 37
7 fpoo werwrw 342 jack 31
执行以下操作:
for row in range(df.shape[0]): # df is the DataFrame
for col in range(df.shape[1]):
if df.get_value(row,col) == 'security_id':
print(row, col)
break
这篇关于 pandas -在DataFrame中的任何位置查找值的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文