How do i get rid of setting with copy warning upon assigining the value of cosine similarity of two dataframes to the column "sim" of dataframe spotify_df and is it something I should worry about.
P.S: user_track_df has only 1 row and spotify_df has around 6000 rows and both have equal number of columns.
Code snippet:
def generate_recommendations(spotify_df, user_track_df):
spotify_df['sim'] = cosine_similarity(spotify_df.drop(['name', 'artists', 'id'], axis=1),
user_track_df.drop(['name', 'artists', 'id'], axis=1))
spotify_df.sort_values(by='sim', ascending=False, inplace=True, kind="mergesort")
spotify_df.reset_index(drop=True, inplace=True)
return spotify_df.head(10)
CodePudding user response:
Most likely your source DataFrame (spotify_df) has been created as a view of another DataFrame.
The side effect is that spotify_df does not have its own data buffer. Instead it shares the data buffer with the DataFrame it has been created from.
To get rid of this warning: When you create spotify_df, add .copy()
to the code.
This way spotify_df will be an "independent" DataFrame, with its
own data buffer, so you can do with it anything you want.