Buenas a toda la comunidad. Estoy haciendo un proyecto sobre un sistema recomendador simple. Utilizando la libreria Pandas
de Python
quiero llenar un dataframe con las coincidencias entre las preferencias del usuario y las peliculas a recomendar.
Tengo 2 .csv
, una con las peliculas y otro con los ratings. Ambos tienen movieId y si existen coincidecias, pero no se genera el dataframe con esas coincidencias. Solo me pone:
Empty DataFrame
Columns: [movieId, Genre, Lead Studio, Audience score %, Profitability, Rotten Tomatoes %, Worldwide Gross, Year, Film, rating]
Index: []
Ahora les pongo parte del codigo y si necesitan mas datos, no duden en decirme. Gracias de antemano. PD.: La parte del ratings no lo mostre porque pienso que ahora poco relevante.
import pandas as pd
from math import sqrt
import numpy as np
import matplotlib.pyplot as plt
peliculas = pd.read_csv('movies.csv')
rating = pd.read_csv('ratings.csv')
# crea columnas y utliza la tecnica One Hot Encoding para codificar las peliculas
peliculas_co = peliculas.copy()
for index, row in peliculas.iterrows(): #pasa x toda la matriz original
for genre in row ['Genre']:
peliculas_co.at[index, genre] = 1 #asigna 1 a cada genero que pertenezca y se guarda en la copia
peliculas_co = peliculas_co.fillna(0) #asignar 0 a cada genero k no pertenezca
print('Peliculas Codificadas:\n', peliculas_co) #muestra las peliculas
Al final de la tabla, estan los 1 y 0 que se le asignan a cada genero
movieId Film Genre Lead Studio Audience score % Profitability Rotten Tomatoes % Worldwide Gross Year R o m a n c e C d y D r A i t F s
0 1 Zack and Miri Make a Porno Romance The Weinstein Company 70 1.747542 64 $41.94 2008 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 2 Youth in Revolt Comedy The Weinstein Company 52 1.090000 68 $19.62 2010 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 3 You Will Meet a Tall Dark Stranger Comedy Independent 35 1.211818 43 $26.66 2010 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 4 When in Rome Comedy Disney 44 0.000000 15 $43.04 2010 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 5 What Happens in Vegas Comedy Fox 72 6.267647 28 $219.37 2008 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
72 73 Across the Universe Romance Independent 84 0.652603 54 $29.37 2007 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
73 74 A Serious Man Drama Universal 64 4.382857 89 $30.68 2009 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0
74 75 A Dangerous Method Drama Independent 89 0.448645 79 $8.97 2011 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0
75 76 27 Dresses Comedy Fox 71 5.343622 40 $160.31 2008 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
76 77 (500) Days of Summer Comedy Fox 81 8.096000 87 $60.72 2009 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
A continuacion se agrega la identificacion a cada pelicula ingresadas por el usuario. Se filtran las filas que contienen el titulo de la pelicula y se fusiona con la matriz de peliculas original.
Id = peliculas[peliculas['Film'].isin(entrada_peli['Film'].tolist())] # Filtro
entrada_peli = pd.merge(Id, entrada_peli) # Fusion de matrices
entrada_peli = pd.DataFrame(entrada_peli)
print('Peliculas filtradas para el Usuario:\n', entrada_peli)
En este punto es dondese se genera el error del Dataframe vacio que describo en el principio ¿pueden ayudar?
Empty DataFrame
Columns: [movieId, Genre, Lead Studio, Audience score %, Profitability, Rotten Tomatoes %, Worldwide Gross, Year, Film, rating]
Index: []
Aqui le muestro parte del dataset de movie:
movieId,Film,Genre,Lead Studio,Audience score %,Profitability,Rotten Tomatoes %,Worldwide Gross,Year
1,Zack and Miri Make a Porno,Romance,The Weinstein Company,70,1.747541667,64,$41.94 ,2008
2,Youth in Revolt,Comedy,The Weinstein Company,52,1.09,68,$19.62 ,2010
3,You Will Meet a Tall Dark Stranger,Comedy,Independent,35,1.211818182,43,$26.66 ,2010
4,When in Rome,Comedy,Disney,44,0,15,$43.04 ,2010
5,What Happens in Vegas,Comedy,Fox,72,6.267647029,28,$219.37 ,2008
6,Water For Elephants,Drama,20th Century Fox,72,3.081421053,60,$117.09 ,2011
7,WALL-E,Animation,Disney,89,2.896019067,96,$521.28 ,2008
8,Waitress,Romance,Independent,67,11.0897415,89,$22.18 ,2007
9,Waiting For Forever,Romance,Independent,53,0.005,6,$0.03 ,2011
10,Valentine's Day,Comedy,Warner Bros.,54,4.184038462,17,$217.57 ,2010
Aqui estan los dataset de ratings
UserId,movieId,Rating,Timestamp
1,61,10,1381620027
1,25,10,1379466669
2,25,8,1394818630
2,72,7,1389963947
2,6,8,1379963769
2,2,7,1391173869
2,45,7,1391529691
2,32,8,1380453043
2,27,8,1387016442
2,42,8,1386350135
dataset
como texto para que podamos probar. A simple vista yo creo que un problema es que Id se genera de una rebanada deldataframe
peliculas sin utilizarloc
oiloc
.