title: Python pandas: How to sort one of multiple groupby columns to be in a specific/custom order?
body: <p>I want to groupby two columns (&quot;Year&quot;, and &quot;Size&quot;) 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:</p>
  <pre><code>df.groupby([&quot;Year&quot;, &quot;Size&quot;])[&quot;Accidents&quot;].count()
  </code></pre>
  <p>the output is like:</p>
  <p><a href="https://i.stack.imgur.com/3gw7m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3gw7m.png" alt="enter image description here" /></a></p>
  <p><strong>My question is: how to sort one of the groupby columns (&quot;Size&quot;) to be in a specific or custom order, such as (V_low, Low, Medium, and High)?</strong> I need also to drop the rows for only the &quot;Size&quot; column if they are nan</p>
  <p>The result should be like that:</p>
  <p><a href="https://i.stack.imgur.com/kr9mW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kr9mW.png" alt="enter image description here" /></a></p>
  <p>thanks for helping</p>