Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

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
Comment

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
Comment

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
Comment

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
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: python pytest use same tests for multiple modules 
Python :: double digest fasta files 
Python :: index operator in python without input 
Python :: useful functions in python 
Python :: write str in a formal way in python 
Python :: remove color from shapefile python 
Python :: one line test python 
Python :: 2d arrary.push in python 
Python :: pie chart labeling 
Python :: how to app object pyhthon 
Python :: mostFrequentDays python 
Python :: dataframe conditional formatting max values 
Python :: select randomly from list in loop 
Python :: pandas join non-unique 
Python :: python class private variables 
Python :: factorielle python 
Python :: set colour to inserplaintext qtextedit in python 
Python :: repalce na with mean per group 
Python :: how to get current user info in odoo 8 in a controller 
Python :: rotch randn 
Python :: is Cross policy an issue with puppeteer / headless chrome? 
Python :: python how to get variable value in dict 
Python :: tensorflow conv2d operation 
Python :: install sorting 
Python :: download textdocuments with python 
Python :: np.ma.filled 
Python :: list all subdirectories up to a level 
Python :: codeforces 233 a solution python 
Python :: python how to close the turtle tab on click 
Python :: help with given object return documentation 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =