Question
We have to obtain a movie id as input from the user . After obtaining the user input how to fetch all movies from the
We have to obtain a movie id as input from the user . After obtaining the user input how to fetch all movies from the database which have at least one genre common with user input and have at least one rating identical to that of one of user input's ratings.(using python pandas dataframe).
eg: if A is the movie id obtained from the user and A has genres "Romantic|Comedy" and has fetched ratings "4.5, 3.0, 2.5", all Romantic or Comedy movie that have obtained at least one rating of 4.5 or 3.0 or 2.5 would be output. There are 2 csv files - movies.csv , ratings.csv which have movie_id as the common column.
movies.csv ----> movie_id, movie_name, genre
ratings.csv ----> movie_id, ratings_given
I have found a solution to this question but I am getting error. Can someone help me with the problem?
import pandas as pd
movies = pd.read_csv('movies.csv')
ratings = pd.read_csv('ratings.csv')
movie_id = input()
movie_genres = movies[movies['movie_id'] == movie_id]['genre'].values[0].split('|')
movie_ratings = ratings[ratings['movie_id'] == movie_id]['ratings_given'].values
recommended_movies = movies[movies['genre'].isin(movie_genres) & movies['ratings_given'].isin(movie_ratings)]
print(recommended_movies)
Error is as shown on the image.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started