from pandas import *

ratings = read_csv("./ml/ratings.csv")
movies  = read_csv("./ml/movies.csv")
tags    = read_csv("./ml/tags.csv")


#as_index = False generate new sequential indices
avg_ratings = ratings.groupby('movieId', as_index = False).mean()
avg_ratings.head()
del avg_ratings[ 'userId']
del avg_ratings[ 'timestamp']
In [7]:
avg_ratings.head()
Out[7]:
movieIdrating
013.920930
123.431818
233.259615
342.357143
453.071429
In [8]:
box_office = movies.merge(avg_ratings, on = 'movieId', how = 'inner')
box_office.tail()
Out[8]:
movieIdtitlegenresrating
9719193581Black Butler: Book of the Atlantic (2017)Action|Animation|Comedy|Fantasy4.0
9720193583No Game No Life: Zero (2017)Animation|Comedy|Fantasy3.5
9721193585Flint (2017)Drama3.5
9722193587Bungo Stray Dogs: Dead Apple (2018)Action|Animation3.5
9723193609Andrew Dice Clay: Dice Rules (1991)Comedy4.0
In [10]:
is_highly_rated = box_office['rating'] >= 4.0
is_highly_rated.head()
Out[10]:
0    False
1    False
2    False
3    False
4    False
Name: rating, dtype: bool
In [13]:
box_office[is_highly_rated][ : 10]
Out[13]:
movieIdtitlegenresrating
2728Persuasion (1995)Drama|Romance4.227273
2829City of Lost Children, The (Cité des enfants p...Adventure|Drama|Fantasy|Mystery|Sci-Fi4.013158
3640Cry, the Beloved Country (1995)Drama4.250000
4650Usual Suspects, The (1995)Crime|Mystery|Thriller4.237745
4853Lamerica (1994)Adventure|Drama5.000000
5055Georgia (1995)Drama4.000000
5258Postman, The (Postino, Il) (1994)Comedy|Drama|Romance4.027027
6674Bed of Roses (1996)Drama|Romance4.000000
6977Nico Icon (1995)Documentary4.000000
7280White Balloon, The (Badkonake sefid) (1995)Children|Drama4.000000
In [15]:
is_commedy = box_office['genres'].str.contains('Comedy')

box_office[is_commedy & is_highly_rated][-10 : ]
Out[15]:
movieIdtitlegenresrating
9680184997Love, Simon (2018)Comedy|Drama4.0
9694188189Sorry to Bother You (2018)Comedy|Fantasy|Sci-Fi4.5
9697188751Mamma Mia: Here We Go Again! (2018)Comedy|Romance4.5
9698188797Tag (2018)Comedy4.0
9699188833The Man Who Killed Don Quixote (2018)Adventure|Comedy|Fantasy4.5
9708190209Jeff Ross Roasts the Border (2017)Comedy4.0
9713191005Gintama (2017)Action|Adventure|Comedy|Sci-Fi4.5
9716193571Silver Spoon (2014)Comedy|Drama4.0
9719193581Black Butler: Book of the Atlantic (2017)Action|Animation|Comedy|Fantasy4.0
9723193609Andrew Dice Clay: Dice Rules (1991)Comedy4.0


+ Recent posts