0
votes

i am stuck to visualize scatter plot, as i got this error message: TypeError: unhashable type: 'slice'

genre_color={'Animation': 'r', 'Horror': 'b', 'Thriller': 'y', 'Drama': 'm', 'Comedy': 'deeppink', 'Sci-Fi': 'gold', 'Western': 'orange', 'Adventure': 'g', 'Documentary': 'brown', 'Musical': 'indigo', 'Fantasy': 'yellow', 'Mystery': 'purple', 'Film-Noir': 'cyan', '(no genres listed)': 'coral', 'Action': 'teal', 'War': 'black', 'Romance': 'skyblue', 'Children': 'lime', 'Crime': 'darkgreen'}

def join_movieDataFrames(pcaDF, genreDF):
x_scaled = preprocessing.scale(pcaDF, with_std=False)
pca = decomposition.PCA(n_components=2)
df_trans = pd.DataFrame(pca.fit_transform(x_scaled),index=df_A.index)
x = pd.merge(df_trans, genreDF, on='movieId')
return plt.scatter(x[:,0],x[:,1],c=data['genre_color'])
(df_A, df_B) = construct_data('ratings.csv', 'movies.csv')
(exVar, df_T) = apply_pca(df_A, 2)
join_movieDataFrames(df_T, df_B)
1

1 Answers

0
votes

You're trying to extract values from a dataframe through slicing syntax, which raises the TypeError.

You should use the iloc property of the dataframe along with values to access that data:

return plt.scatter(x.iloc[:,0].values ,x.iloc[:,1].values,c=data['genre_color'])

iloc is the dataframe property that allows integer-location based indexing, and values removes the labels returning only the actual values.