Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. games_data['genre'] = games_data['genre'].fillna('unknown')
  2. games_data['user_score'] = games_data['user_score'].replace({'tbd': np.nan})
  3. games_data['user_score'] = games_data['user_score'].astype(float)
  4.  
  5. def fill(col):    
  6.     for platform in games_data.platform.unique():
  7.         median_dict = games_data.query('platform == @platform').groupby('genre')[col].median()
  8.         for genre in games_data.query('platform == @platform').genre.unique():
  9.             games_data.loc[(games_data['platform'] == platform) & (games_data['genre'] == genre) & (np.isnan(games_data[col])), col] = median_dict.loc[genre]
  10.  
  11.            
  12.        
  13.        
  14.    
  15.    
  16. fill('critic_score')  
  17. fill('user_score')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement