📜  Python|熊猫 dataframe.quantile()

📅  最后修改于: 2022-05-13 01:54:19.670000             🧑  作者: Mango

Python|熊猫 dataframe.quantile()

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas dataframe.quantile()函数返回请求轴上给定分位数的值,一个 numpy.percentile。

注意:在变量的任何一组值中,将频率分布分成相等的组,每个组包含总人口的相同比例。

示例 #1:使用quantile()函数查找“.2”分位数的值

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.DataFrame({"A":[1, 5, 3, 4, 2],
                   "B":[3, 2, 4, 3, 4],
                   "C":[2, 2, 7, 3, 4], 
                   "D":[4, 3, 6, 12, 7]})
  
# Print the dataframe
df

让我们使用dataframe.quantile()函数来查找数据帧中每一列的 '.2' 的分位数

# find the product over the index axis
df.quantile(.2, axis = 0)

输出 :

示例 #2:使用quantile()函数沿索引轴查找 (.1, .25, .5, .75) 分位数。

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.DataFrame({"A":[1, 5, 3, 4, 2],
                   "B":[3, 2, 4, 3, 4],
                   "C":[2, 2, 7, 3, 4],
                   "D":[4, 3, 6, 12, 7]})
  
# using quantile() function to
# find the quantiles over the index axis
df.quantile([.1, .25, .5, .75], axis = 0)

输出 :