Skip to content

Instantly share code, notes, and snippets.

@dradecic
Created September 29, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dradecic/7a65cac23c59c8206417ec26a6411641 to your computer and use it in GitHub Desktop.
Save dradecic/7a65cac23c59c8206417ec26a6411641 to your computer and use it in GitHub Desktop.
recommender1_5_rating_by_genre
values = defaultdict(list)
for ind, row in data.iterrows():
for genre in row['genres'].split('|'):
values[genre].append(row['rating'])
genre_lst, rating_lst = [], []
for key, item in values.items():
if key not in [0, 1]:
genre_lst.append(key)
rating_lst.append(np.mean(item))
genres_with_ratings = pd.DataFrame([genre_lst, rating_lst]).T
genres_with_ratings.columns = ['Genre', 'Mean_Rating']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment