Python 参数:值错误:序号应为>;=1.
我有以下系列,称为Python 参数:值错误:序号应为>;=1.,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有以下系列,称为sr In [1]: sr Out[1]: 0 0 1 0 2 0 3 0 4 0 5 1 6 2 7 4 8 7 9 4 10 3 11 2 12 1 13 2
sr
In [1]: sr
Out[1]: 0 0
1 0
2 0
3 0
4 0
5 1
6 2
7 4
8 7
9 4
10 3
11 2
12 1
13 2
14 2
15 2
16 4
17 7
18 7
19 5
20 3
21 2
22 1
23 1
dtype: int64
我想画出这个系列,连同滚动平均数。为此,我使用以下代码:
import matplotlib.pyplot as plt
import pandas as pd
rolling = pd.rolling_mean(sr, 3, center=True)
ax_delays = sr.plot(style='--', color='b')
rolling.plot(color='b', ax=ax_delays, legend=0)
plt.title('Title')
plt.ylim(ymax=10)
plt.show()
但这给了我以下错误:
ValueError Traceback (most recent call last)
1 rolling = pd.rolling_mean(sr, 3, center=True)
----> 2 ax_delays = sr.plot(style='--', color='b')
3 rolling.plot(color='b', ax=ax_delays, legend=0)
4 plt.title('Title')
5 plt.ylim(ymax=10)
ValueError: ordinal must be >= 1
此错误是什么意思?我如何修复它?如果运行
plt.clf()
这将清除内存中的绘图,并允许继续绘图(在中断绘图例程后遇到此错误时对我有效)。如果运行plt.clf()
这将清除内存中的绘图,并允许继续绘图(在中断绘图例程后遇到此错误时对我有效)。这对我有效,您正在运行哪个版本?我正在使用0.16.0是的,我也在使用0.16.0。也许重新启动IPython笔记本会起作用。你能显示sr.index
的输出吗?sr.index
给我Int64Index([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],dtype='int64')
奇怪,看起来还可以。你能提供一个小的可重复的例子吗?(生成一些再现问题的数据的代码)这对我有效,您正在运行哪个版本?我正在使用0.16.0是的,我也在使用0.16.0。也许重新启动IPython笔记本会起作用。你能显示sr.index
的输出吗?sr.index
给我Int64Index([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],dtype='int64')
奇怪,看起来还可以。你能提供一个小的可重复的例子吗?(生成再现问题的某些数据的代码)