text_plain_output_1.png image_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

ratings_df = pd.read_csv('../input/u.data', sep='\t', names=['user_id', 'movie_id', 'rating', 'ts'])
ratings_df

movie_df = pd.read_csv('../input/u.item', sep='|', encoding='latin-1', header=None)
movie_df = movie_df[[0, 1]]
movie_df.columns = ['movie_id', 'movie_name']
movie_df

mean_ratings = ratings_df.groupby('movie_id').agg({'rating': 'mean'}).reset_index().rename({'rating': 'mean_rating'}, axis=1)
count_ratings = ratings_df.groupby('movie_id').agg({'rating': 'count'}).reset_index().rename({'rating': 'count_rating'}, axis=1)
mean_ratings

base_model_df = movie_df.merge(mean_ratings).merge(count_ratings)
base_model_df