I have a dataframe that contains every movie in a certain genre and the year it was released (plus some other stuff). I want to reorganize the dataframe so that it contains the number of films per year (and each year appears only once). Is there a way to do this?
Asked
Active
Viewed 21 times
0
-
Could you please add a [mre](https://stackoverflow.com/help/minimal-reproducible-example) (also look [here](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) to your question? ([How do I ask a good question?](https://stackoverflow.com/help/how-to-ask)) – Timus Dec 06 '21 at 09:03
-
Please provide enough code so others can better understand or reproduce the problem. – Community Dec 10 '21 at 17:04
1 Answers
0
You should look into groupby and value_counts
For instance,
df.groupby("year")["genre"].value_counts()
will show you the number of movies in each genre for each year.
Without seeing your data and things you've tried I can't help much more. Please try to show these things.

Wesley Cheek
- 1,058
- 12
- 22