I essentially have a data frame like this:
year genre
2018 drama
2019 comedy
2019 drama
2019 comedy
2019 comedy
I want to group it such that I get the count of each genre by year AND the total count for the year. Something like this
year genre count total count
2018 drama 1 1
2019 comedy 3 4
2019 drama 1 4
What I am doing right now is a simple group by like this
df.groupby(['year', 'genre']).count()
But this obviously only gives me a count by the genre. How can I include the total count for the year in this?
I am sorry for any formatting issues.