Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import pandas as pd
  2. hogwarts_points = pd.read_csv('/datasets/hogwarts_points_eng.csv')
  3. hogwarts_points['house'] = hogwarts_points['house'].fillna(value='Gryffindor')
  4. print ('Total points for Hogwarts:', hogwarts_points['points'].sum(), 'total sum of points') # total of values in the 'points' column
  5. print ('Total points by house:', hogwarts_points.groupby('house')['points'].sum().sum(), 'total points with grouping by house') # group by the 'house' column
  6. # then use the sum() method to add the points, which are the values in the 'points' column for this grouping
  7. # and apply the sum() method to the results
  8. print('The Cup goes to', hogwarts_points.groupby('house')['points'].sum().idxmax(), 'house name')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement