Python Pandas Series.quantile()

Python Pandas Series.quantile()

Pandas系列是一个带有轴标签的一维ndarray。标签不需要是唯一的,但必须是一个可散列的类型。该对象支持基于整数和标签的索引,并提供了大量的方法来执行涉及索引的操作。

Pandas Series.quantile()函数返回给定系列对象中基础数据的给定quantile值。

语法: Series.quantile(q=0.5, interpolation=’linear’)

参数:
q :浮动或类似数组,默认为0.5(50%的四分位数)。
interpolation : {‘线性’, ‘较低’, ‘较高’, ‘中点’, ‘最近’}

示例#1:使用Series.quantile()函数来返回给定Series对象中基础数据的所需四分法。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
  
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
  
# set the index
sr.index = index_
  
# Print the series
print(sr)

输出 :

Python Pandas Series.quantile()

现在我们将使用Series.quantile()函数来查找给定系列对象中基础数据的40%的四分位数。

# return the value of 40 % quantile
result = sr.quantile(q = 0.4)
  
# Print the result
print(result)

输出 :

Python Pandas Series.quantile()

正如我们在输出中看到的,Series.quantile()函数成功地返回了给定Series对象的基础数据的预期qunatile值。

示例#2:使用Series.quantile()函数来返回给定Series对象中基础数据的所需四分法。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([11, 21, 8, 18, 65, 84, 32, 10, 5, 24, 32])
  
# Print the series
print(sr)

输出 :

Python Pandas Series.quantile()

现在我们将使用Series.quantile()函数来查找给定系列对象中基础数据的90%的四分位数。

# return the value of 90 % quantile
result = sr.quantile(q = 0.9)
  
# Print the result
print(result)

输出 :

Python Pandas Series.quantile()

正如我们在输出中看到的,Series.quantile()函数成功地返回了给定Series对象的基础数据的预期qunatile值。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程