Home > Net >  How to use count, groupby and max in pandas?
How to use count, groupby and max in pandas?

Time:07-28

I want to use the sql operations count, groupby, max in pandas in the following condition.

My dataframe df

call_count    Date       Call Received Appointments
1           5/21/2021     Y                N
2           5/21/2021     Y                N
3           5/21/2021     Y                N
1           5/22/2021     Y                Y
2           5/22/2021     Y                N
1           5/23/2021     N                N

I want to group by these data under Date and calculate max of call_count and also count Y and N of Call Received and Appointment.

The expected output will be:

Total_call_count Date       Total Received Call Total Appointments
3                5/21/2021     3                  0
2                5/22/2021     2                  1
1                5/23/2021     0                  0

CodePudding user response:

You can replace value Y with True and N with False then use enter image description here

  • Related