python - How to sum values of particular rows in pandas? -
i not familiar python yet. have pandas data frame looks this:
          0         1     2     3 55   alice   12896399     8    45 45   bob     16891982     0     0 90   cybill   1800407     1     1 05   alice   12896399   100   200 33   bob     16891982   0.5     0 42   bob     16891982  -1.5  -0.5 46   bob     16891982     1     0 99   cybill   1800407  0.00  0.00   how can sum values of columns 2 , 3 result each person? this:
   alice     108    245    bob       0     -0.5    cybill    1     1   thank in advance reply.
iiuc can groupby , sum on cols of interest:
in [13]: df.groupby('0')[['2','3']].sum()  out[13]:             2      3 0                    alice   108.0  245.0 bob       0.0   -0.5 cybill    1.0    1.0      
Comments
Post a Comment