Skip to content
Advertisement

How do I plot the frequency of an event overtime with pandas?I

I was trying to plot some data from a pandas dataframe. My table contains 10000ish films and for each of them two info: the year it got published, and a rating from 0 to 3. I am having a hard time trying to plot a graph with the pandas library that shows the number of films that received a particular rating (3 in my case) every year.

I have tried to use .value_counts(), but it didn’t work as i hoped, since I can’t isolate a single value, maintaining the rating linked to its year.

I really hoped i decently explained my problem, since it is the first time i ask help on stack overflow.

This is the code i used to get my dataframe, if it is useful in any way.

JavaScript

P.S. Thank you for the precious help!

Advertisement

Answer

You can filter by rating and use Series.value_counts:

JavaScript

But there is many years of films:

JavaScript

So for plot I filter only counts greatwer like 30, it is 40 years here:

JavaScript

So filter again and plot:

JavaScript

EDIT: Solution with percentages:

JavaScript

EDIT1: Here is solution for count years vs ratings:

JavaScript

EDIT2:

JavaScript

There is alot of values, here is e.g. filter for column 3 for more like 60% values:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement