Check if a value exists in pandas dataframe index

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.

    df = pandas.DataFrame({'test':[1,2,3,4]}, index=['a','b','c','d'])

    df.loc['g']  # (should give False)

What I have working now is the following

    sum(df.index == 'g')

This should do the trick

    'g' in df.index

From: stackoverflow.com/q/23549231

Back to homepage or read more recommendations: