Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

groupby sum and mean 2 columns

d = {'Missed':'Sum1', 'Credit':'Sum2','Grade':'Average'}
df=df.groupby('Name').agg({'Missed':'sum', 'Credit':'sum','Grade':'mean'}).rename(columns=d)
print (df)
      Sum1  Sum2  Average
Name                     
A        2     4       11
B        3     5       15
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #groupby #sum #columns
ADD COMMENT
Topic
Name
7+1 =