Consider that I have one dataframe that looks like this:
Gender Employed
1 1
0 0
1 0
0 1
And I have another dataframe that looks like:
Name Area
Andy Gender
Ally HR
Chris Employed
Tom Food
I only want to keep the row entries in the area column that correspond to the column names of my first dataframe. These are example dataframes and my actual dataframe has hundreds of columns so no very specific answers involving ‘Gender’ and ‘Employed’ will work.
The end result should be
Name Area
Andy Gender
Chris Employed
>Solution :
You can filter a df like this:
df[df['Area'].isin(df2.columns)]