From a Pandas newbie: I have data that looks essentially like this -
data1=pd.DataFrame({'Dir':['E','E','W','W','E','W','W','E'], 'Bool':['Y','N','Y','N','Y','N','Y','N'], 'Data':[4,5,6,7,8,9,10,11]}, index=pd.DatetimeIndex(['12/30/2000','12/30/2000','12/30/2000','1/2/2001','1/3/2001','1/3/2001','12/30/2000','12/30/2000']))
data1
Out[1]:
Bool Data Dir
2000-12-30 Y 4 E
2000-12-30 N 5 E
2000-12-30 Y 6 W
2001-01-02 N 7 W
2001-01-03 Y 8 E
2001-01-03 N 9 W
2000-12-30 Y 10 W
2000-12-30 N 11 E
And I want to group it by multiple levels, then do a cumsum():
E.g., like running_sum=data1.groupby(['Bool','Dir']).cumsum()
<-(Doesn't work)
with output that would look something like:
Bool Dir Date running_sum
N E 2000-12-30 16
W 2001-01-02 7
2001-01-03 16
Y E 2000-12-30 4
2001-01-03 12
W 2000-12-30 16
My "like" code is clearly not even close. I have made a number of attempts and learned many new things about how not to do this.
Thanks for any help you can give.