Skip to content

Instantly share code, notes, and snippets.

@lucascheung
Created April 8, 2020 15:22
Show Gist options
  • Save lucascheung/87040518649a91e4f2a2a3c8c1ed234e to your computer and use it in GitHub Desktop.
Save lucascheung/87040518649a91e4f2a2a3c8c1ed234e to your computer and use it in GitHub Desktop.
pandas groupby method with other columns
df = df.groupby(['client_id','data_source'],as_index=False).agg({
'client': 'first',
'currency': 'first',
'total_revenue': 'sum',
'total_accrual': 'sum',
'revenue': 'sum',
'media_cost': 'sum'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment