使用 x 和 y 中的特定值创建直方图
Create histogram with specific values in x and y
我有以下数据框
COD DATE QTD MOV SUM
1 15295 2021-01-22 1 10.0 3
3 15801 2020-12-04 1 10.0 1
4 23369 2021-01-01 1 7.5 6
11 32012 2020-07-26 1 10.0 2
12 37726 2020-06-30 1 10.0 1
我想制作一个直方图,其中 x 轴上有来自列 SUM(排序)的值,y 轴上是在 x 轴上具有 SUM 值的 COD 的数量。
我尝试制作直方图并移动垃圾箱的数量,但收效甚微。
也许必须用条形图来完成?但是如何 select 我想把什么放在 y 轴上呢?谁能帮帮我?
使用Series.value_counts
with Series.reindex
and then Series.plot.bar
:
r = range(df['SUM'].min(), df['SUM'].max() + 1)
s = df['SUM'].value_counts().reindex(r, fill_value=0)
print (s)
1 2
2 1
3 1
4 0
5 0
6 1
Name: SUM, dtype: int64
s.plot.bar()
或使用Series.plot.hist
:
df['SUM'].plot.hist()
我有以下数据框
COD DATE QTD MOV SUM
1 15295 2021-01-22 1 10.0 3
3 15801 2020-12-04 1 10.0 1
4 23369 2021-01-01 1 7.5 6
11 32012 2020-07-26 1 10.0 2
12 37726 2020-06-30 1 10.0 1
我想制作一个直方图,其中 x 轴上有来自列 SUM(排序)的值,y 轴上是在 x 轴上具有 SUM 值的 COD 的数量。 我尝试制作直方图并移动垃圾箱的数量,但收效甚微。 也许必须用条形图来完成?但是如何 select 我想把什么放在 y 轴上呢?谁能帮帮我?
使用Series.value_counts
with Series.reindex
and then Series.plot.bar
:
r = range(df['SUM'].min(), df['SUM'].max() + 1)
s = df['SUM'].value_counts().reindex(r, fill_value=0)
print (s)
1 2
2 1
3 1
4 0
5 0
6 1
Name: SUM, dtype: int64
s.plot.bar()
或使用Series.plot.hist
:
df['SUM'].plot.hist()