In PANDAS, how to get the index of a known value?

前端 未结 5 570
一生所求
一生所求 2021-01-30 01:41

If we have a known value in a column, how can we get its index-value? For example:

In [148]: a = pd.DataFrame(np.arange(10).reshape(5,2),columns=[\'c1\',\'c2\'         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 02:23

    There might be more than one index map to your value, it make more sense to return a list:

    In [48]: a
    Out[48]: 
       c1  c2
    0   0   1
    1   2   3
    2   4   5
    3   6   7
    4   8   9
    
    In [49]: a.c1[a.c1 == 8].index.tolist()
    Out[49]: [4]
    

提交回复
热议问题