Python 为分类数据绘制直方图

Python 为分类数据绘制直方图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有一个包含两列的数据集,如下所示: index Year 0 5 <2012 1 8 >=2012 2 9 >=2012 3 10 <2012 4 15 <2012 ... ... ... 171 387 >=2012 172 390 <2012 173 398 <2012 174 403 >=2012 175 409 <2012 但我有一个错误:AttributeError:'Cat

我有一个包含两列的数据集,如下所示:

    index   Year
0   5   <2012
1   8   >=2012
2   9   >=2012
3   10  <2012
4   15  <2012
... ... ...
171 387 >=2012
172 390 <2012
173 398 <2012
174 403 >=2012
175 409 <2012
但我有一个错误:
AttributeError:'CategoricalIndex'对象没有属性'remove\u unused\u levels'

df.groupby(['Year'])\
          .Year.count().unstack().plot.bar(legend=True)
我想这是因为我使用的是分类值。任何帮助都将不胜感激。

请尝试:

plt.style.use('ggplot')
df.groupby(["Year"])["Year"].agg("count").plot.bar();

或者:

plt.hist(df["Year"]);
试试:

plt.style.use('ggplot')
df.groupby(["Year"])["Year"].agg("count").plot.bar();

或者:

plt.hist(df["Year"]);