0

I have a pandas dataframe like so: enter image description here

I want to be able to output this into a summary by price point kinda like this:

face_value | section | count |

   50.5    |    101  |    200

   50.5    |    301  |    365

where count is the cumulative total of all sections where available = True and for that specific price point. It's possible that the same section has multiple face values, so i would hope to aggregate them separately. Let's say I had multiple face_values for section 101, here would be the output if there was only section 101 in this data.

face_value | section | count |

   50.5    |       101    |      200

   97.5    |       101    |      365

So basically I would like to group by the price points and sum the counts if availability is true and ticket_type is primary. Looking through the pandas documentation and I'm having issues figuring anything out.

cs95
  • 379,657
  • 97
  • 704
  • 746
sevpants
  • 365
  • 1
  • 2
  • 10
  • 2
    Please look at [this article](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) about how to ask a good pandas question. – Scott Boston Nov 08 '17 at 14:51

1 Answers1

0

You can use groupby and cumsum i.e

df[df['availability'] == True].groupby(['section','face'])['count'].cumsum().reset_index()
Bharath M Shetty
  • 30,075
  • 6
  • 57
  • 108
  • The issue with this is that it doesn't output the section or the value of the price, the only two columns that output are index and count. I would want [section, face_value, count] as my columns. – sevpants Nov 08 '17 at 15:12
  • Would have been better if you put text data. – Bharath M Shetty Nov 08 '17 at 15:22