Finding index of a pandas DataFrame value

Use a boolean mask to get the rows where the value is equal to the random variable. Then use that mask to index the dataframe or series. Then you would use the .index field of the pandas dataframe or series. An example is:

In [9]: s = pd.Series(range(10,20))

In [10]: s
Out[10]:

0    10
1    11
2    12
3    13
4    14
5    15
6    16
7    17
8    18
9    19
dtype: int64

In [11]: val_mask = s == 13

In [12]: val_mask

Out[12]:
0    False
1    False
2    False
3     True
4    False
5    False
6    False
7    False
8    False
9    False
dtype: bool

In [15]: s[val_mask]
Out[15]:
3    13
dtype: int64

In [16]: s[val_mask].index
Out[16]: Int64Index([3], dtype='int64')

s[s==13]

Eg,

from pandas import Series

s = Series(range(10,20))
s[s==13]

3    13
dtype: int64