I am sure there is an obvious way to do this but cant think of anything slick right now.
Basically instead of raising exception I would like to get True
or False
to see if a value exists in pandas df
index.
JavaScript
x
4
1
import pandas as pd
2
df = pd.DataFrame({'test':[1,2,3,4]}, index=['a','b','c','d'])
3
df.loc['g'] # (should give False)
4
What I have working now is the following
JavaScript
1
2
1
sum(df.index == 'g')
2
Advertisement
Answer
This should do the trick
JavaScript
1
2
1
'g' in df.index
2