I have 3 cols in dataframe, [Rank, prev, original], i want to develop logic as : when prev==original, rank should be 1 else rank equals rank+1. please help me write this using apply lambda.
Thanks in advance
A better approach would be to use pandas Fancy indexing
:
df[df['prev'] == df['original']]['Rank'] = 1
df[df['prev'] != df['original']]['Rank'] += 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.