Suppose you have the below data frame called raw
:
A B C
Index
2007-01-03 NaN -1 1
2007-01-04 0.021954 1 2
2007-01-05 -0.007147 -1 3
2007-01-08 0.004926 1 4
2007-01-09 0.079800 1 4
2007-01-10 0.046746 1 4
2007-01-11 -0.012448 -1 5
2007-01-12 -0.012394 -1 5
2007-01-16 0.025873 1 6
2007-01-17 -0.022391 -1 7
2007-01-18 -0.063928 -1 7
2007-01-19 -0.006420 -1 7
2007-01-22 -0.019511 -1 7
2007-01-23 -0.012639 -1 7
2007-01-24 0.011601 1 8
2007-01-25 -0.005204 -1 9
2007-01-26 -0.010138 -1 9
2007-01-29 0.006538 1 10
2007-01-30 -0.004549 -1 11
2007-01-31 0.002102 1 12
How can I groupby columns B & the count of column C while also summing column A? Am able to produce the former via raw[['B','C']].value_counts()
(grouping by column B and count of C) but unable to combine this result with the latter (sum of column A).
raw[['B','C']].value_counts()
B C
-1 7 5
1 4 3
-1 5 2
9 2
1 1
3 1
11 1
1 2 1
6 1
8 1
10 1
12 1
dtype: int64