get index of value pandas code example

Example 1: finding the index of an element in a pandas df

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]

Example 2: finding the index of an item in a pandas df

print(df[df['Name']=='Donna'].index.values)

Example 3: python get index and value from list

test = [ 'test 1', 'test 2', 'test 3' ]
for index, value in enumerate( test ):
  print( index, value )

Example 4: get index number pandas dataframe

df.index[df['BoolCol'] == True].tolist()