Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python group by multiple aggregates

def f(x):
    d = {}
    d['a_sum'] = x['a'].sum()
    d['a_max'] = x['a'].max()
    d['b_mean'] = x['b'].mean()
    d['c_d_prodsum'] = (x['c'] * x['d']).sum()
    return pd.Series(d, index=['a_sum', 'a_max', 'b_mean', 'c_d_prodsum'])

df.groupby('group').apply(f)
Comment

PREVIOUS NEXT
Code Example
Python :: robust scaler 
Python :: how to append a number to a list in python 
Python :: file base name and extension python 
Python :: how to start a new django project 
Python :: merge two series by index 
Python :: python find intersection of two lists 
Python :: create an array of n same value python 
Python :: python slice string 
Python :: python coding questions and answers 
Python :: hardest python questions 
Python :: object to int and float conversion pandas 
Python :: xor string python 
Python :: color name to hex python 
Python :: streamlit python install 
Python :: test split 
Python :: change matplotlib fontsize 
Python :: opencv invert image 
Python :: prime number in python 
Python :: print last exceuted query python 
Python :: python operators 
Python :: change to first letter capital list python 
Python :: pd.read_excel column data type 
Python :: readlines from file python 
Python :: image on jupyter notebook 
Python :: visitor IP address django 
Python :: python code to generate fibonacci series 
Python :: flask-callable 
Python :: openpyxl fast tutorial 
Python :: pandas sep 
Python :: root mean squared error python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =