python - Finding the sum of grouped data by column -
my grouped data looks like:
deviceid                                  time          total_sent 022009f075929be71975ce70db19cd47780b112f  1980-january  36            4                                                         52            1                                                         94            1                                                         211           1                                                         278           1                                                         318           2                                                         370           1                                                         426           1                                                         430           1                                                         435           1                                                         560           1                                                         674           1                                                         797           1                                                         813           4                                                         816           1  ff5b22df4ab9207bb6709cddef6d95c655565578  2013-august  11308408       4                                                        12075616       1                                                        17933654       1                                                        22754808      12                                                        22754987       1                                                        22755166       3                                                        22755345       4                                                        22788586       4                                                        22788765       2                                                        22788944       2                                                        22791830       1                                                        22792546       1                                                        22796843       1                                                        22797201       2                                                        22797380       2   where last column represents count. obtained grouped representation using expression:
data1.groupby(['deviceid', 'time', 'total_sent'])   how sum total_sent per month?
deviceid                                  time            sum     022009f075929be71975ce70db19cd47780b112f  1980-january    6210 ff5b22df4ab9207bb6709cddef6d95c655565578  2013-august     xxxx                
since total_sent column summed, shouldn't within groupby keys. can try following:
data1.groupby(['deviceid', 'time']).agg({'total_sent': sum})   which sum total_sent column each group, indexed deviceid , time.
Comments
Post a Comment