I am trying to find a string in all columns of a dataframe.
import pandas as pd
df = pd.DataFrame([['a', 'b'], ['c', 'd'], ['e', 'a']], columns=["A", "B"])
for col in df:
df[col].str.contains('a')
0 True
1 False
2 False
Name: A, dtype: bool
0 False
1 False
2 True
Name: B, dtype: bool
However, the code above returns only the booleans and not the format that I want (displays the rows and columns in table form), which can be achieved when searching in a specific column:
df[df.A == 'a']
A B
0 a b
Can anyone help?