如何堆叠 value_count 和条形图的结果

How to stack the resuls from a value_count & bargraph

我有一个 value_count().sort_index() 基于伯尔尼州 'categorynumber'of .csv 文件的列

bern['categorynumber'].value_counts().sort_index()

结果是: 左|正确的 :---| ----: 1.1 | 781 1.2 | 185 1.3 | 319 1.4 | 79 1.5 |170 1.6 | 3个 1.7 | 20 2.1 |199 2.2 |856 2.3 | 63 2.4 |504 3.1 |139 3.2 |2​​89 3.3 | 21 4.1 |366 4.2 | 276 4.3 |41 4.4 | 49 4.5 | 120 4.6 | 2285 4.7 | 478 5.1 | 65 5.2 | 137 5.3 | 75 5.4 | 46 名称:类别编号,数据类型:int64

现在我想

  • create a bargraph but

    df.plot (x = 'categorynumber', y = amount, kind = 'bar') does not seem to function as I have not defined the right (in the column) calculations as 'amount' so how do I do that?

显然 plot 函数比你更清楚要绘制什么,所以把它留给它并只指定 kind:

s.plot(kind='bar')

(我将你的 value_count().sort_index() s 命名为 df 因为它是 系列,不是DataFrame。)

  • create a table and bars (graph) based on the sum of 1.1-1.7; 2.1-2.4; 3.1-3.3; 4.1-4.7; 5.1-5.4 is that possible? if yes, how?

在你的例子中,对象将被索引的整数部分分割,这很容易:

t = s.groupby(int).sum()
t.plot(kind='bar')