title: Pandas - Aggregating and Plotting Results
body: <p>I have what I think should be a fairly simple question, but I have been fighting with it for hours</p>
  
  <p>I want to do an aggregation on a pandas dataframe and then plot it using matplotlib</p>
  
  <p>I start with a huge table of years and models of cars.   I then want to calculate the aggregate sales price and a percentage of asking prices.</p>
  
  <p>I do that as follows</p>
  
  <pre><code>percent_asking_price =(df.groupby(['year','model'])['salesprice'].sum()/df.groupby(['year','model'])['askingprice'].sum())*100
  </code></pre>
  
  <p>That seems to do what I want it to do, but then I don't know what to do with the output - it returns output that looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/kgJAS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kgJAS.jpg" alt="Sample Output Data"></a></p>
  
  <p>From that point on, I can't figure out what to do with it.. I want to graph the combination of year and model name using matplotlib to make it look something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/rtKaQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rtKaQ.jpg" alt="Sample Chart"></a></p>
  
  <p>A bit frustrated because this is something I can do really quickly using ddply and ggplot in r, but just can't get anywhere here</p>
  
  <p>I have tried converting the output to a dataframe, but that didnt get me anywhere</p>
  
  <p>Would really appreciate help</p>
  
  <p>A small set that will show the results follows:</p>
  
  <pre><code>year,model,salesprice,askingprice
  2009,Taurus,25410,30000
  2009,Taurus,8698,10000
  2009,Maxima,11135,15000
  2009,Maxima,8500,10000
  2010,Corvette,25000,30000
  2010,Corvette,18320,20000
  2010,Trans Am,32000,35000
  2010,Trans Am,23620,25000
  </code></pre>
  
  <p>Finally  -is there a way to convert the output to a dataframe that looks as follows, so I can do further work on the output?  I don't want to lose the values in the first column..</p>
  
  <p><a href="https://i.stack.imgur.com/JTfC1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JTfC1.jpg" alt="enter image description here"></a></p>
  
  <p>Thanks!</p>