Consider the series s below:
s
s = pd.Series(np.arange(18, 0, -3), list(\'ABCDEF\')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int
Use np.searchsorted -
np.searchsorted(s.index.values,'D')
Or use the method, like so -
s.index.searchsorted('D')
You can use Index.get_loc:
print(s.index.get_loc('D')) 3
m = s.index == 'D' idx = m.argmax() if m.any() else None