I have a dataframe with the string "name" appearing and I want to count the appearance of it for each column. I would like the results in a new df.
import pandas as pd
data1 = {'first_column': ['1', '2', 'name'],
'second_column': ['name', 'name', 'name'],
'id_number':['name', '4', 'name'],
'fourth_column':['5', 'name', '2'],
}
df1 = pd.DataFrame(data1)
I tried this but this gave me this output but I don't have a new df and have too many results:
for col in df1:
df2 = df1[df1[col] == "name"].count()
print(df2)

