Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- games_data['genre'] = games_data['genre'].fillna('unknown')
- games_data['user_score'] = games_data['user_score'].replace({'tbd': np.nan})
- games_data['user_score'] = games_data['user_score'].astype(float)
- def fill(col):
- for platform in games_data.platform.unique():
- median_dict = games_data.query('platform == @platform').groupby('genre')[col].median()
- for genre in games_data.query('platform == @platform').genre.unique():
- games_data.loc[(games_data['platform'] == platform) & (games_data['genre'] == genre) & (np.isnan(games_data[col])), col] = median_dict.loc[genre]
- fill('critic_score')
- fill('user_score')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement