title: Summing and plotting by month and arbitrary attribute in Pandas
body: <p>I'm currently getting into data analysis and am building a little accounting app to keep track of my expenses.</p>
  <p>My goal is to track my expenses in a Django app, make some analyses with Pandas on it and visualize it with Matplotlib.</p>
  <p>My data basis comes from a Django ORM query like this:</p>
  <pre><code>qs = MyExpenses.objects.values('date', 'amount', 'category')
  </code></pre>
  <p>Then I use Pandas' <code>from_records</code> method to create an indexed DataFrame:</p>
  <pre><code>df = pd.DataFrame.from_records(qs, index='date', coerce_float=True)
  df.index = pd.to_datetime(df.index)  # manually make index a proper DateTimeIndex, datetime.date objects don't seem to be converted automatically
  </code></pre>
  <p>Checking the DataFrame's content with <code>df.head()</code>:</p>
  <pre><code>            amount  category
  date        
  2017-12-29  14.90   Food
  2017-12-27  2.98    Household
  2017-12-27  9.72    Food
  2017-12-24  2.00    Food
  2017-12-23  1.49    Household
  </code></pre>
  <p>Looking good so far.</p>
  <p>At this point I don't know how to correctly proceed. <strong>I want to have my expenses summed up per category per month.</strong></p>
  <p>This groupby operation:</p>
  <pre><code>summed_df = df.groupby([pd.Grouper(freq='1M'), 'category']).sum()
  </code></pre>
  <p>Returns the correctly aggregated data:</p>
  <pre><code>                                amount
  date        category    
  2016-02-29  Cosmetics           2.45
              Food                376.41
              Household           43.82
              Leisure             630.13
  2016-03-31  Food                345.41
              Household           14.76
              Leisure             553.35
  ...
  </code></pre>
  <p>But calling <code>summed_df.plot()</code> renders this plot:
  <a href="https://i.stack.imgur.com/WyG9x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WyG9x.png" alt="enter image description here" /></a></p>
  <p>Obviously Panda uses the combined index of date and category as the x axis and the amount column as a single data series. As stated above, that's not what I want.</p>
  <p>Consequentially I have to do summing in another way or somehow remove category from the index and make it a regular column again, but I have no idea how to approach this.</p>
  <p>Can some of the Pandas cracks out there help me out?</p>