I am trying to create a new data frame from an existing data frame with the count of existing columns in the data frame. Let's assume I have following DataFrame
cus_Type | ID | ID_type |
---|---|---|
R | 100 | X |
S | 100 | Y |
R | 101 | X |
S | 102 | Y |
P | 103 | X |
B | 104 | Y |
P | 105 | X |
B | 106 | Y |
K | 108 | D |
I would like to create a new data Frame from the above with following 'count' of cus_Type ,ID_type like below:
cus_Type | ID_type | count |
---|---|---|
R | X | 2 |
S | Y | 2 |
P | X | 2 |
B | Y | 2 |
K | D | 1 |
I am trying to use pd.groupby(['cus_Type','ID_type']) but not sure how to bring count as a new column in the existing data frame.