我想找出熊猫dataframe
的第20位数,而不是每一栏。我知道.quantile
函数可以沿着一个特定的轴找到分位数,但是,如果它的所有列都是整数,那么是否有一个快速快捷的方法来查找整个dataframe
的分位数?
使用熊猫series
作为中介的期望结果示例:
>>> import pandas as pd
>>> df= pd.DataFrame(data={1: [55, 11, 13, 9, 11],
2: [56, 75, 31, 1, 25]})
>>> df.quantile(.2) # this finds two quantiles, one per column
1 10.6
2 20.2
Name: 0.2, dtype: float64
# The workaround
>>> s = df[1].append(df[2])
>>> s.quantile(.2)
10.6
发布于 2019-08-16 13:10:25
您可以使用numpy的 [numpy-doc]:
>>> import numpy as np
>>> np.quantile(df, 0.2)
10.6
或者我们可以直接使用熊猫模块中的numpy库导入:
>>> pd.np.quantile(df, 0.2)
10.6
发布于 2019-08-16 13:08:54
这是melt
df.melt().value.quantile(0.2)
Out[309]: 10.6
https://stackoverflow.com/questions/57531142
复制相似问题