Issue
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
Solution
We can try to use the cumcount()
method instead of rank()
:
df['date_rank'] = df.groupby(['CookieID'])['PageViewDate'].cumcount() + 1
Answered By - tlentali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.