2017-05-31 32 views
0

我有这个数据帧称为“dfArrivalDate”(如图中的前11行)使用熊猫系列日期XTICK标签

arrival_date count 
0 2013-06-08  9 
1 2013-06-27  8 
2 2013-03-06  8 
3 2013-06-01  8 
4 2013-06-28  6 
5 2012-11-28  6 
6 2013-06-11  5 
7 2013-06-29  5 
8 2013-06-09  4 
9 2013-06-03  3 
10 2013-05-31  3 

sortedArrivalDate = transform.sort('arrival_date') 

我想绘制出来的柱状图中看到到达日期计数。我叫

sortedArrivalDate.plot(kind = 'bar') [![enter image description here][1]] 

但我得到的索引作为我的条形图的行蜱。我想我需要使用'xticks'。

sortedArrivalDate.plot(kind = 'bar', xticks = sortedArrivalDate.arrival_date) 

,但我碰到的错误:类型错误:不能与type“浮动”

我尝试了不同的方法比较类型“时间戳”。

fig, ax = plt.subplots() 
ax.plot(sortedArrivalDate.arrival_date, sortedArrivalDate.count) 

这一次的错误是ValueError异常:X和Y必须具有相同的第一维

我想这可能只是一个简单的办法,因为我没有太多的经验,在大熊猫编码和matplotlib,我可能会在这里错过一件非常简单的事情。关心引导我在正确的方向?谢谢。

回答

1

IIUC:

df = df.sort_values(by='arrival_date') 
df.plot(x='arrival_date', y='count', kind='bar') 

enter image description here