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.
import json
import requests
import pandas as pd
import numpy as np
request = requests.get("http://bechdeltest.com/api/v1/getAllMovies").json()
data = pd.DataFrame(request)
P.S. Thank you for the precious help!
>Solution :
You can filter by rating and use Series.value_counts:
s = data.loc[data['rating'].eq(3), 'year'].value_counts()
But there is many years of films:
print (len(s))
108
So for plot I filter only counts greatwer like 30, it is 40 years here:
print (s.gt(30).sum())
40
So filter again and plot:
s[s.gt(30)].plot.bar()