I think the problem here is with RangeIndex
when we try to do the division. Try convert index to numpy:
popRanked = [(100, 50), (215, 3) , (500,4)]
n = len(popRanked)
df = pd.DataFrame(np.array(popRanked), columns=["A","B"])
df['Probability'] = 2*(n- df.index.to_numpy()+1 )/(n*(n-1))*100
print(df)
A B Probability
0 100 50 133.333333
1 215 3 100.000000
2 500 4 66.666667
We can also use df.index.values
instead df.index.to_numpy()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…