suppose that I have this dataframe
date id
0 2019-10-01 303
1 2019-10-01 303
2 2019-10-01 404
3 2019-10-01 404
4 2019-10-02 303
5 2019-10-02 303
6 2019-10-02 404
7 2019-10-02 404
I want to apply ranking so that I have this dataframe
date id id_rank
0 2019-10-01 303 1
1 2019-10-01 303 1
2 2019-10-01 404 1
3 2019-10-01 404 1
4 2019-10-02 303 2
5 2019-10-02 303 2
6 2019-10-02 404 2
7 2019-10-02 404 2
I tried pandas.groupby.rank() with this code
df["id_rank"] = df.groupby(["index_date", "id"])["id"].rank(method="first")
which gets me closer to the wanted result
date id id_rank
0 2019-10-01 303 1
1 2019-10-01 303 1
2 2019-10-01 404 1
3 2019-10-01 404 1
4 2019-10-02 303 1
5 2019-10-02 303 1
6 2019-10-02 404 1
7 2019-10-02 404 1
I want to rank based on date. If the id is registered in the dataframe for the first day, it takes rank 1 and if it's registered again on the second day, it takes rank 2 and so on; rank 3 if the id is registered on a third day