【发布时间】:2016-03-27 20:32:32
【问题描述】:
我正在绘制“每周总事件”的几个熊猫系列对象。系列events_per_week中的数据是这样的:
Datetime
1995-10-09 45
1995-10-16 63
1995-10-23 83
1995-10-30 91
1995-11-06 101
Freq: W-SUN, dtype: int64
我的问题如下。所有 pandas 系列的长度相同,即从 1995 年开始。然而,一个数组从 2003 年开始。 events_per_week2003 始于 2003 年
Datetime
2003-09-08 25
2003-09-15 36
2003-09-22 74
2003-09-29 25
2003-09-05 193
Freq: W-SUN, dtype: int64
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,5))
ax = plt.subplot(111)
plt.plot(events_per_week)
plt.plot(events_per_week2003)
我收到以下值错误。
ValueError: setting an array element with a sequence.
我该怎么做?
【问题讨论】:
-
您可以将每一列提取到一个变量中,然后绘制(x,y)。您的代码中的
events_per_week是什么?一个系列? -
@tglaria 'events_per_week' 是一个始于 1995 年的系列。
-
@tglaria 我不明白这个“你可以将每一列提取到一个变量中,然后绘制(x,y)”
-
我的意思是将第 1 列存储为日期数组,将第 2 列存储为浮点数组,然后将
plot(column 1, column 2)存储,尽管我确信有一种直接的绘制方法。 -
好的,您可以使用
events_per_week.plot('Datetime', 'name_of_other_column')和plt.show()进行绘图
标签: python pandas matplotlib time-series