熊猫情节值+人数(=数值)

时间:2018-02-08 11:55:13

标签: python pandas dataframe plot

IHello伙计们,我实际上无法找到我的基本问题的答案。 所以我有2列

     Age   Headcount
0    30         8
1    36         3
2    41         5
3    42         4
4    44         1
5    46         6
6    47         3
7    48         4
8    49         5
9    50         1
10   52         2
11   54         4
12   55         1
13   57         3
14   58         1
15   61         8

如果我这样做

DataFrame.plot(x=DataFrame.Age, y=DataFrame.Headcount)
我已经

KeyError: '[8 3 5 4 1 6 3 4 5 1 2 4 1 3 1 8] not in index'

即使我将Headcount列作为索引,我也会有类似的错误。

我可以做一个新的pd.Series有八个30,三个36等等并绘制它,但它确实可以从我的orignal DataFrame中做到。

感谢帮助。

1 个答案:

答案 0 :(得分:2)

试试这个 -

DataFrame.plot(x='Age', y='Headcount')

<强>解释

根据Pandas Documentation -

  

x:标签或位置,默认无

     

y:标签或位置,默认无

     

允许绘制一列与另一列

指定标签就足够了,你不需要明确地传递这个系列!