I am using some aggregation function after doing the groupby on a pandas dataframe, like:
my_df.groupby(['id']).agg(['count'])
I am wondering is it possible to have a customized aggregation function? For example, in my data frame:
id color
--------------------
001 red
001 blue
001 yellow
002 green
002 black
003 yellow
003 white
003 blue
I want to create a customized function called all_color, so I could do something like:
my_df.groupby(['id']).agg(['all_color'])
and get the output data frame as:
id all_color
--------------------
001 [red,blue,yellow]
002 [green,black]
003 [yellow,white,blue]