image_output_1.png
import json

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import numpy as np

import pandas as pd

import seaborn as sns

import seaborn as sns

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
dir = '/kaggle/input/the-movies-dataset/'
ratings = pd.read_csv(dir + 'ratings_small.csv')
metadata = pd.read_csv(dir + 'movies_metadata.csv', low_memory=False)

metadata = metadata.rename(columns={'id': 'movieId'})
metadata['movieId'] = pd.to_numeric(metadata['movieId'], errors='coerce')
combined_data = pd.merge(ratings, metadata, on='movieId')
df_grouped = combined_data.groupby(['movieId', 'userId'])['rating'].mean().reset_index()
wide_df = df_grouped.pivot(index='userId', columns='movieId', values='rating')
df_clean = wide_df.dropna(thresh=20, axis=1)
df_clean

import json
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
combined_data['release_date'] = pd.to_datetime(combined_data['release_date'], errors='coerce')
def parse_genres(genres_str):
    genres = json.loads(genres_str.replace("'", '"'))
    genres_list = [g['name'] for g in genres]
    return genres_list
combined_data['genres'] = combined_data['genres'].apply(parse_genres)
combined_data['release_year'] = combined_data['release_date'].dt.year

all_genres = np.concatenate(combined_data['genres'].values)
unique_genres, counts = np.unique(all_genres, return_counts=True)
genre_counts = pd.DataFrame({'genre': unique_genres, 'count': counts}).sort_values(by='count', ascending=False)

plt.figure(figsize=(10, 5))
sns.barplot(x='genre', y='count', data=genre_counts)
plt.title('Distribution of Genres')
plt.xlabel('Genre')
plt.ylabel('Count')
plt.xticks(rotation=90)
plt.show()