'Panda Dataframe Append function

After making my Recommendation System Content based, I want to get the recommendation score for one user based on his story movie_id list : my user data df2 look like this : enter image description here

my top 5 movies Recommendation data for selected one movie_id looks like that(result of my get_recommendations function) :

enter image description here

I want to create a new table for one user that give recommendation score and movie-id for each movie_id in df2, this is the code that I tried :

for i in range(0,len(df2)):
  movie_id=df2['movie'].iloc[i]
  movie_indices, scores = get_recommendations_indices(movie_id, cosine_sim, indices)
  movie_recommended = get_recommendations(movie_id, descriptions_data, movie_indices, scores, top=5)
  appended_data = pandas.DataFrame.append(movie_recommended)
  i+=1

But I get this error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/databricks/python/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3079             try:
-> 3080                 return self._engine.get_loc(casted_key)
   3081             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'id-000-C'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)

Anyone can help please ? Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source