I'm trying to calculate the speed rank of drivers by looking at his/her past 20 race. However, i need to get get current value and rolling values to function. Here what i did so far:
def set_rank(x, y):
return stats.percentileofscore(x,y)
df['Rank'] = df['SpeedRank'].rolling(20).apply(lambda x: set_rank(x, df['SpeedRank']), raw=True)
The problem is y
how can i send value of corresponding row to the function?
I have solved this problem. Here is the solution:
def set_rank(x):
return stats.percentileofscore(x,x[-1])
df['Rank'] = df['SpeedRank'].rolling(20).apply(set_rank, raw=True)
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.