I have the following code with groupby function
order_diff = order.groupby("CD_QTY").filter(
lambda x: x["BOX_ID"].nunique() > 1
)
But the filter function is very slow
I would like to use the transform or map function. But the result with both transform and map function is different than the filter function
I have tried transform() and map()
# tranform
oder_diff = order[order.groupby("CD_QTY")["BOX_ID"].transform('nunique').gt(1)]
#using map()
order[order["CD_QTY"].map(order.groupby("CD_QTY")["BOX_ID"].nunique()).gt(1)]
I am a bit confused about why the results are different than the filter(). I would appreciate your feedback on this. Thank you.