I have a DataFrame with one month's data:
initiated_date | specialist_id | rating
21/10/2020 05:00:01 | ab12 | 8.1
21/10/2020 12:20:01 | gc35 | 7.3
22/10/2020 04:30:01 | ad32 | 6.4
22/10/2020 03:40:01 | fe45 | 9.2
22/10/2020 01:50:01 | ad32 | 8.2
23/10/2020 02:10:01 | iu99 | 8.7
23/10/2020 11:30:01 | iu99 | 7.9
I want to breakdown per week for the top 5 specialists with respect to average rating. I am trying to replicate the rank partition by function of sql here.
What I am looking for is:
Week | specialist_id | avg.rating | ranking
22 | ab12 | 9.8 | 1
22 | gb22 | 9.1 | 2
22 | po90 | 8.8 | 3
22 | nh78 | 8.3 | 4
22 | hj89 | 8.1 | 5
23 | bg77 | 9.7 | 1
23 | ab12 | 9.5 | 2
This is what I am trying to do
df.groupby([df['initiated_date'].dt.week])['rating'].mean().reset_index()
I am not sure how to go further.