0

I am working on the movielens dataset, I would like to create a new column by applying a function , the basic idea is : 1) get corresponding movie id from the ratings_dataframe 2)use this movie id to find the name of the movie from moviesdata_frame 3)and copy this value to the corresponding cell in the ratings dataframe

My code consists of:

def getname(p):
    nm =  movies.loc[movies['movie_id'] == 'p']['title']
    return nm   



ratings['title'] = ratings.apply(lambda row:getname(gg['movie_id']))

The error is :('invalid type comparison', u'occurred at index movie_id')

1 Answer 1

1

You don't need a function for this simple mapping:

ratings_dataframe['title'] = \
    ratings_dataframe['movie_id'].map(movies.set_index('movie_id')['title'])
Sign up to request clarification or add additional context in comments.

2 Comments

Works like charm.
Is it possible to do the same without using the set_index function ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.