如何获得 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("Enter the percentile you want to calculate: "))
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 Enter the percentile you want to calculate: 50 The 50.0 percentile of the given series is: 30.0
说明
Pandas 库中的 quantile 函数的参数取值为 0 到 1 之间的值。因此,在将百分位数传递给 quantile 函数之前,我们必须将百分位数值除以 100。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP