I'm making a bot for Telegram with recommendation system in it. There's a part of code:
search_word = str(message.text)
movie_search = movies[movies['title'].str.contains(search_word)]
user_movie_matrix['movieId'], movie_search = user_movie_matrix['movieId'].align(movie_search, axis=0, copy=False)
movie_id = user_movie_matrix[user_movie_matrix['movieId'].eq(movie_search)].index[0]
However, I'm getting this warning:
FutureWarning: Automatic reindexing on DataFrame vs Series comparisons is deprecated and will raise ValueError in a future version. Do `left, right = left.align(right, axis=1, copy=False)` before e.g. `left == right`
movie_id = user_movie_matrix[user_movie_matrix['movieId'].eq(movie_search)].index[0]
Even if I change axis from 0 to 1, it'll get me this:
ValueError: No axis named 1 for object type Series
I tried also to swap places, but it ended up with one of two errors. Not writing user_movie_matrix['movieId'], movie_search = user_movie_matrix['movieId'].align(movie_search, axis=0, copy=False)
also gaves first error.
You get this warning because you're comparing the Series user_movie_matrix['movieId']
with the DataFrame movie_search
. You can remove the warning by specifying the relevant column of movie_search
:
movie_ids = user_movie_matrix[user_movie_matrix['movieId'].eq(movie_search['movieId'])]
However, since the comparison occurs element-wise, you'd probably prefer to use isin
:
movie_ids = user_movie_matrix[user_movie_matrix['movieId'].isin(movie_search['movieId'])]
(changing variable name since it is likely to return multiple rows)