From d0fb8668c1158fd17a803ebd3fda0b01014b7021 Mon Sep 17 00:00:00 2001 From: Oli Steadman Date: Thu, 3 May 2018 12:25:39 +0100 Subject: [PATCH] pandas: Split-apply-combine (2 funcs: count, mean) --- .../snippets_menu/snippets_submenus_python/pandas.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/snippets_submenus_python/pandas.js b/src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/snippets_submenus_python/pandas.js index b82ed3b4a..74994ba0e 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/snippets_submenus_python/pandas.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/snippets_menu/snippets_submenus_python/pandas.js @@ -113,7 +113,16 @@ define({ { 'name' : 'Combining', - 'snippet' : ['',], + 'sub-menu' : [ + { + 'name' : 'Split-apply-combine (sum)', + 'snippet' : ['df['label_count'] = df.groupby('label', as_index=False)['label'].transform(lambda x: x.count())',], + }, + { + 'name' : 'Split-apply-combine (mean)', + 'snippet' : ['df['label_mean'] = df.groupby('label', as_index=False)['label'].transform(lambda x: x.mean())',], + }, + ], }, {