python - 按百分位数绘制直方图

标签 python pandas

是否有任何库可以根据系列按百分位数绘制直方图?我一直在研究 Pandas ,但我没有看到任何可用的方法。我确实知道一个很长的解决方法,即手动计算我想要的每个百分位数的出现次数。但我认为可能有更好的解决方案。

目前我必须获得个人计数

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

等等……

但是使用描述。我设法得到这个

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

最佳答案

国际联合会

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

关于python - 按百分位数绘制直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43580886/

相关文章:

python - 值错误: need more than 0 values to unpack(python lists)

python - 有兴趣在维基百科 xml 转储中仅搜索与医学相关的术语

python - 如何使用lambda python函数来使用map,如下所示?

python - 动态附加到 Pandas Dataframe

python - 对包含列表的Pandas列进行分组操作

python - 将 pandas DataFrame 列扩展为多行

python - 获取图像中的所有 R-G-B

python - typing.List<~T>[typing.Tuple[int]] 在 Python 类型库中是什么意思?

python - pip 将 google-api-python-client 安装到 PC - 访问被拒绝

python - 解析错误,更新 1 行中的多个列