如何获得 Pandas 系列的第 n 个百分位数?
百分位数是统计中使用的一个术语,用于表示一个分数与同一组中其他分数的比较情况。在这个程序中,我们必须找到Pandas系列的第n个百分位数。
算法
Step 1: Define a Pandas series. Step 2: Input percentile value. Step 3: Calculate the percentile. Step 4: Print the percentile.
示例代码
import pandas as pd
series = pd.Series([10,20,30,40,50])
print("Series:\n", series)
n = int(input("输入要计算的百分位数: "))
n = n/100
percentile = series.quantile(n)
print("The {} percentile of the given series is: {}".format(n*100, percentile))输出结果Series: 0 10 1 20 2 30 3 40 4 50 dtype: int64 输入要计算的百分位数: 50 The 50.0 percentile of the given series is: 30.0
解释
Pandas库中的分位数函数仅将0到1之间的值作为参数。因此,我们必须先将百分位数除以100,然后再将其传递给分位数函数。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下