Using OMDB api to find data about TV shows
In [78]:
import json
import urllib.request as request
We're using two params. t (for title) and Season. Change values as you wish :)
In [163]:
url = 'http://www.omdbapi.com/?t=Scandal&Season=3'
In [164]:
content = request.urlopen(url).read()
In [165]:
data = json.loads(content.decode('UTF-8'))
Now let's take a look at what data we have
In [166]:
print(data)
Okay! As we can see, data are indexed by Episodes. What do we have about the first episode?
In [167]:
print(data['Episodes'][0])
So now we know which attributes each episode has. imdbRating is quite interesting, let's work on that. If we want to find out the rating for the seventh episode, all we gotta do is:
In [170]:
print(data['Episodes'][6]['imdbRating'])
Since we want to analyze data statistically, let's create a list and keep all ratings grouped
In [141]:
ratings = []
for episode in data['Episodes']:
ratings.append(episode['imdbRating'])
In [171]:
print(ratings)
In [142]:
from scipy import stats
What rating can be considered the mode for that season?
In [143]:
mode = stats.mode(ratings)
print(mode)
In [144]:
print(mode[0][0])
How many episodes have been rated like this?
In [139]:
print(mode[1][0])