Daniel Kim
unread,Feb 9, 2012, 8:32:52 PM2/9/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pystatsmodels
Hello,
Is there a built-in running count or cumulative count function in
pandas or numpy. I see there are cumsum functions available both in
pandas and in numpy, but I didn't see something that would get a
cumulative count. Let's say I have a dataframe like so:
df.groupby(['MODEL_YEAR','RO_YR_MTH'])['MILES_TO_FAIL'].count()
Output:
YR_MTH, COUNT
2011-03, 1
2011-04, 1
2011-06, 1
2011-07, 1
2011-08, 1
2011-10, 1
2011-12, 1
I want to create a column that contains a cumulative count like so:
YR_MTH, COUNT, CUM_COUNT
2011-03, 1, 1
2011-04, 1, 2
2011-06, 1, 3
2011-07, 1, 4
2011-08, 1, 5
2011-10, 1, 6
2011-12, 1, 7
Thanks in advance!