I have a Pandas dataset with 3 columns. I need to group by the ID column while finding the sum and count of the other two columns. Also, I have to ignore the zeroes in the columsn 'A' and 'B'.
The dataset looks like -
ID   A    B  
1    0    5  
2   10    0   
2   20    0  
3    0   30   
What I need -
ID   A_Count   A_Sum   B_Count   B_Sum  
1      0         0        1        5  
2      2        30        0        0  
3      0         0        1       30  
I have tried this using one column but wasn't able to get both the aggregations in the final dataset.
(df.groupby('ID').agg({'A':'sum', 'A':'count'}).reset_index().rename(columns = {'A':'A_sum', 'A': 'A_count'}))  
 
     
    