Q:

Trying to find top watched genres per gender based on dataframe with two columns genre and gender

I'm currently working with a large movie dataset, which I have filtered to 2 columns: Genre and Gender.
To visualize this:
Genre:        Gender:
Romance       Male
Tech          Male
Romance       Male
Comedy        Female
Tech          Female
Comedy        Male
Romance       Female
Romance       Male

I want to show the top 3 most viewed genres per gender, but I can't seem to get the right code. 
What I've tried:
df_final_gender['name'].groupby(df_final_gender['GENDER']).describe()

Which shows only the most viewed (top) genre of each gender. I want the top 3 of each gender, any help is appreciated! 

A:

With the following DataFrame:
df = pd.DataFrame({
    'Genre': ['Romance', 'Tech', 'Romance', 'Comedy', 'Tech', 'Comedy', 'Romance', 'Romance',], 
    'Gender': ['Male', 'Male', 'Male', 'Female', 'Female', 'Male', 'Female', 'Male',]})

Add an extra column for counts:
df['value'] = 1

This gives you:
    Genre   Gender  value
0   Romance Male    1
1   Tech    Male    1
2   Romance Male    1
3   Comedy  Female  1
4   Tech    Female  1
5   Comedy  Male    1
6   Romance Female  1
7   Romance Male    1

Then group by the two fields Genre and Gender and get the counts:
counts = df.groupby(['Genre', 'Gender']).count()

Outputs: 
                value
Genre   Gender  
Comedy  Female  1
        Male    1
Romance Female  1
        Male    3
Tech    Female  1
        Male    1

You can sort:
sorted = counts.sort_values(by='value', ascending=False)

And plot:
sorted.plot(kind='bar', figsize=(15,8))

Will get you:

