How to search for a string value on each and every columns using pandas . Lets say I have 32 columns ,
df[df['A'].str.contains("hello")]
this returns whether the value is present in "A" column or not ,How to search on every columns and the row in which the value is exist . Dataset :
A B C
1 hi hie
2 bye Hello
If I search for "hello" or "Hello" output should be :
A B C
2 bye Hello
s = df.stack() # convert entire data frame into a series of values df.iloc[s[s.str.contains('hello',na=False)].index.get_level_values(0)]# see below post for details on how it works