I am trying to create a new column with .groupby(), .apply() and a custom function. However, I can\'t work out how to get good performance.
I have tried the code below, w