I have an object that I got from performing a groupby(["A", "B"] combined with .nlargest(3) function in pandas.
i.e:
df.groupby(["A", "B"])["Column"].nlargest(3).reset_index().unstack()
Now I have 3 values per "A" "B". I did an unstack and it works, but I hit the memory capacity and it crashes sometimes.
I somewhat remember finding a (built-in) solution to this very problem long ago, but couldn't find it again. Apologies if this is a duplicate and thanks in advance!