How can I group data into months from dates where a data frame has both categorical and numerical data in pandas. I tried the groupby function but I think it won't work with categorical data. There are multiple values in the categorical column. Sample data:
Date | Campaign_Name | No_of_Male_Viewers | No_of_Female_Viewers |
---|---|---|---|
2021-06-12 | Dove_birds | 1268 | 7656 |
2021-02-05 | Pantene_winner | 657 | 8964 |
2021-09-15 | Budweiser_wazap | 7642 | 76 |
2021-05-13 | Pantene_winner | 425 | 6578 |
2021-12-12 | Budweiser_wazap | 9867 | 111 |
2021-09-09 | Dove_birds | 1578 | 11456 |
2021-05-24 | Pantene_winner | 678 | 7475 |
2021-09-27 | Budweiser_wazap | 8742 | 96 |
2021-09-09 | Dove_soft | 1175 | 15486 |
Now I need to group the data months wise and show for example that Budweiser_wazap in September gained a total audience of xxxx and in December gained xxxx audience and so on for the other campaigns as well.
Expected output sample:
Month | Campaign_Name | No_of_Male_Viewers | No_of_Female_Viewers |
---|---|---|---|
February | Pantene_winner | 657 | 8964 |
September | Budweiser_wazap | 16384 | 172 |
Since Budweiser_wazap campaign ran twice in September, the resulting output for No_of_Male_Viewers is: 7642 + 8742 = 16384, and for No_of_Female_Viewers is: 76 + 96 = 172.