ValueError:在绘制整数的数据框列时,x和y必须具有相同的第一维

问题描述 投票:0回答:1

我有一个带有年/月列和一个int列的数据框。看起来像这样:

         Date     count
0  2018-01-01  19730570
1  2018-02-01  19301103
2  2018-03-01  21962470
3  2018-04-01  21034792
4  2018-05-01  21556113
5  2018-06-01  21118266
6  2018-07-01  21584891
7  2018-08-01  22101502
8  2018-09-01  22123605
9  2018-10-01  23266816
10 2018-11-01  22861081

我正在尝试使用matplot将其绘制成图形,但我不断收到一个错误,即我的x和y是不同的尺寸,但显然它们不是。

ValueError: x and y must have same first dimension, but have shapes (11,) and (1,)

我已经将日期列转换为日期时间,但仍不确定为什么会收到此错误。

这是我要执行的内容:

plt.plot(monthly_trips_fhv.Date, monthly_trips_fhv.count)

python pandas matplotlib
1个回答
0
投票
  • [pandas.DataFrame.count是一种数据框方法。
  • 您的列名称正在镜像该方法名称,因此您需要使用pandas.DataFrame.count
monthly_trips_fhv['count']

import pandas as pd import matplotlib.pyplot as plt plt.plot(monthly_trips_fhv.Date, monthly_trips_fhv['count']) plt.xticks(rotation=90) plt.show()

© www.soinside.com 2019 - 2024. All rights reserved.