I want to groupby two columns ("Year", and "Size") and then get the count for the number of accidents associated with each size. I was able to do that by this line of code:
df.groupby(["Year", "Size"])["Accidents"].count()
the output is like:
My question is: how to sort one of the groupby columns ("Size") to be in a specific or custom order, such as (V_low, Low, Medium, and High)? I need also to drop the rows for only the "Size" column if they are nan
The result should be like that:
thanks for helping