Skip to content

Instantly share code, notes, and snippets.

@ctufts
Created July 29, 2016 18:06
Show Gist options
  • Save ctufts/3d280f19f116eb17b924e9ff4976266f to your computer and use it in GitHub Desktop.
Save ctufts/3d280f19f116eb17b924e9ff4976266f to your computer and use it in GitHub Desktop.
group by and apply a function with multiple input arguments (PANDAS)
# ds has columns A, B, C, - group by A, then use B and C as inputs in the
# MSE calculation
grouped = ds.groupby('A')
mse = grouped.apply( lambda x: metrics.mean_squared_error(x['B'], x['C']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment