title: Sort a pandas dataframe series by month name
body: <p>I have a Series object that has:</p>
  
  <pre><code>    date   price
      dec      12
      may      15
      apr      13
      ..
  </code></pre>
  
  <p><strong>Problem statement:</strong> I want to make it appear by month and compute the mean price for each month and present it with a sorted manner by month.</p>
  
  <p>Desired Output:</p>
  
  <pre><code> month mean_price
    Jan    XXX
    Feb    XXX
    Mar    XXX
  </code></pre>
  
  <p>I thought of making a list and passing it in a sort function:</p>
  
  <pre><code>months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  </code></pre>
  
  <p>but the <em>sort_values</em> doesn't support that for series.</p>
  
  <p>One big problem I have is that even though</p>
  
  <p><code>df = df.sort_values(by='date',ascending=True,inplace=True)</code> works
  to the initial <code>df</code> but after I did a <code>groupby</code>, it didn't maintain the order coming out from the sorted <code>df</code>.</p>
  
  <p>To conclude, I needed from the initial data frame these two columns. Sorted the datetime column and through a groupby using the month (dt.strftime('%B')) the sorting got messed up. Now I have to sort it by month name.</p>
  
  <hr>
  
  <p>My code:</p>
  
  <pre><code>df # has 5 columns though I need the column 'date' and 'price'
  
  df.sort_values(by='date',inplace=True) #at this part it is sorted according to date, great
  total=(df.groupby(df['date'].dt.strftime('%B'))['price'].mean()) # Though now it is not as it was but instead the months appear alphabetically
  </code></pre>