3

Is there any function to check if a value exists in any rows of any columns in pandas, such as

columnA columnB columnC
"john" 3 True
"mike" 1 False
"bob" 0 False

on the dataframe above, I want to know if there are any values named "mike" in any elements of the whole dataframe, and if it exists, I'd like to get True - otherwise get False.

Thanks.

Blaszard
  • 29,431
  • 45
  • 147
  • 228

1 Answers1

13

Something like this:

df.apply(lambda x: 'mike' in x.values, axis=1).any()

or

df.applymap(lambda x: x == 'mike').any().any()
Roman Pekar
  • 99,839
  • 26
  • 181
  • 193