need help. i have a sample data which contains sessionid and datetime visited. one session may be visited multiple pages in the same day. i need to assign ranking for each date group by the session.
the code which i am using is
df['date_rank'] = df.groupby(['CookieID'])['PageViewDate'].rank().astype(int)
but it is not giving expected rank
the output is
We can try to use the cumcount()
method instead of rank()
:
df['date_rank'] = df.groupby(['CookieID'])['PageViewDate'].cumcount() + 1