gpt4 book ai didi

python - 具有 2 列和已知频率的 Pandas 直方图

转载 作者:行者123 更新时间:2023-11-30 22:35:35 35 4
gpt4 key购买 nike

我有一个数据框 df,如下所示:

    INDEX     VAL
0 1 23.0
1 250001 23.0
2 500001 23.0
3 750001 18.0
4 1000001 0.0

如何绘制直方图,其中 x 轴为索引,y 为 VAL 值,直方图条形为 1-250001、250001-500001 等?

例如,从 1-250001 条形图的高度应为 23。

最佳答案

既然你已经有了频率,你需要的是一个条形图;您可以调整绘图参数,使其看起来像直方图:

import matplotlib
%matplotlib inline
ax = df.set_index('INDEX').plot(kind="bar", color="#dd55ff", position=0, width=1.0, rot=0)

enter image description here

关于python - 具有 2 列和已知频率的 Pandas 直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44524980/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com