我正在尝试查找数据集中每个数据的百分位。我可以输入所需的百分位数并接收价格,但我希望能够输入价格并接收百分位数并将其扩展到我的整个数据集。
Price Percentile
2018-01-31 121
2018-04-30 12.8
2018-07-30 141
2018-10-31 90
2019-01-31 120
2019-04-30 51.194
最佳答案
您想要 pd.Series.rank
与 pct=True
df.assign(Percentile=df.Price.rank(pct=True))
Price Percentile
2018-01-31 121.000 0.833333
2018-04-30 12.800 0.166667
2018-07-30 141.000 1.000000
2018-10-31 90.000 0.500000
2019-01-31 120.000 0.666667
2019-04-30 51.194 0.333333
关于python - python 中的百分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43226894/