# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

df1 = pd.read_csv("E:/dataset/movies.csv")
df2 = pd.read_csv("E:/dataset/ratings.csv")
dfs = pd.merge(df1, df2)

dfs.head(10)

dfs.shape

dfs.info()

dfs.describe()

dfs.groupby('title')['rating'].mean().sort_values(ascending=False).head() 


dfs.groupby('title')['rating'].count().sort_values(ascending=False).head() 

# +
ratings = pd.DataFrame(dfs.groupby('title')['rating'].mean())  
  
ratings['num of ratings'] = pd.DataFrame(dfs.groupby('title')['rating'].count()) 
  
ratings.head() 
# -

movie = dfs.pivot_table(index ='userId', columns ='title', values ='rating') 
movie.head()

ratings.sort_values('num of ratings', ascending = False).head(10)

# +
forrestgump_user_ratings = movie['Forrest Gump (1994)'] 
braveheart_user_ratings = movie['Braveheart (1995)'] 
  
forrestgump_user_ratings.head() 

# +
similar_to_forrestgump = movie.corrwith(forrestgump_user_ratings) 
similar_to_braveheart = movie.corrwith(braveheart_user_ratings) 
  
corr_forrestgump = pd.DataFrame(similar_to_forrestgump, columns =['Correlation']) 
corr_forrestgump.dropna(inplace = True) 
  
corr_forrestgump.head() 

# +
corr_forrestgump.sort_values('Correlation', ascending = False).head(10) 
corr_forrsetgump = corr_forrestgump.join(ratings['num of ratings']) 
  
corr_forrestgump.head() 
  
corr_forrsetgump[corr_forrestgump['num of ratings']>100].sort_values('Correlation', ascending = False).head() 

# +
corr_braveheart = pd.DataFrame(similar_to_braveheart, columns =['Correlation']) 
corr_braveheart.dropna(inplace = True) 
  
corr_braveheart = corr_braveheart.join(ratings['num of ratings']) 
corr_braveheart[corr_braveheart['num of ratings']>100].sort_values('Correlation', ascending = False).head() 
# -



StarcoderdataJupyterScriptsDedupFiltered