用百分位数绘制直方图

时间:2017-04-24 06:09:10

标签: python pandas

是否有基于系列的百分位数绘制直方图的库?我一直在挖熊猫,但我没有看到任何可用的方法。我知道一个很长的解决方法,即手动计算我想要的每个百分位数的出现次数。但我认为可能有更好的解决方案。

目前我需要获得个人收入

# Sample series 
tenth = df.col.quantile(0.1) 
twenty = df.col.quantile(0.2) 
twenty_count = len(twenty - tenth)

等等......

然而使用describe。我设法得到了这个

df.describe(percentiles = [x/10.0 for x in range(1,11)]

1 个答案:

答案 0 :(得分:4)

IIUC

df.col.rank(pct=True).hist()

然而,这是一个坏主意。

考虑以下数据框df

df = pd.DataFrame(dict(
        col=np.random.randn(1000),
        col2=np.random.rand(1000)
    ))

然后

df.col.rank(pct=True).hist()

enter image description here

这是一张愚蠢的图表。

相反,除以最大绝对值

(df / df.abs().max()).hist()

enter image description here