0

I have a dataframe df as

Decile    2_Con    3_Con    6_Con   Pred
   1        0        0        0       0
   1        0        0        1       1
   1        0        0        1       1
   2        0        0        0       0
   2        0        1        0       1
   2        0        1        1       1

Objective:

I want to compute the count of 6_Con, 3_Con and 2_Con when I filter the above df by Pred and set 6_Con ,3_con and 2_Con to 1 for each Decile.

So the resultant Dataframe should look like:

   Decile      2_Con     3_Con      6_Con    Pred
     1           0         0          2        2      <--We are only counting 1 in the columns for each Decile
     2           0         2          1        2      

How to achieve this? I am not able to generate a plausible code here.

Thanks in advance

pythondumb
  • 1,187
  • 1
  • 15
  • 30

1 Answers1

0

Did you try:

df = df.groupby('Decile').sum()

This makes sense because of the 0-1 values, hence, the sum will be the count of non 0 values (rows) for each different decile.

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53