Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 打印数据帧引发的序数值错误必须为>;=1._Python_Matplotlib_Pandas - Fatal编程技术网

Python 打印数据帧引发的序数值错误必须为>;=1.

Python 打印数据帧引发的序数值错误必须为>;=1.,python,matplotlib,pandas,Python,Matplotlib,Pandas,我在一个网站上学习教程 我有一个熊猫数据框 2012年3月天气['Temp(摄氏度)] 当我试图绘制它时,我得到了一个错误 weather_mar2012['Temp (°C)'].plot(figsize=(15, 5)) --------------------------------------------------------------------------- ValueError Traceback (mos

我在一个网站上学习教程

我有一个熊猫数据框

2012年3月天气['Temp(摄氏度)]

当我试图绘制它时,我得到了一个错误

weather_mar2012['Temp (°C)'].plot(figsize=(15, 5))



--------------------------------------------------------------------------- 
ValueError                                Traceback (most recent call last) <ipython-input-31-21c79ba7d5ef> in <module>()
----> 1 weather_mar2012['Temp (°C)'].plot(figsize=(15, 5))

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)    2486                  yerr=yerr, xerr=xerr,    2487                  label=label, secondary_y=secondary_y,
-> 2488                  **kwds)    2489     2490 

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)    2292         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)    2293 
-> 2294     plot_obj.generate()    2295     plot_obj.draw()    2296     return plot_obj.result

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in generate(self)
    922         self._make_legend()
    923         self._post_plot_logic()
--> 924         self._adorn_subplots()
    925 
    926     def _args_adjust(self):

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _adorn_subplots(self)    1052                     ax.set_xticklabels(xticklabels)    1053                 self._apply_axis_properties(ax.xaxis, rot=self.rot,
-> 1054                                            fontsize=self.fontsize)    1055             elif self.orientation == 'horizontal':    1056                 if self._need_to_set_index:

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _apply_axis_properties(self, axis, rot, fontsize)    1061     1062  def _apply_axis_properties(self, axis, rot=None, fontsize=None):
-> 1063         labels = axis.get_majorticklabels() + axis.get_minorticklabels()    1064         for label in labels:    1065             if rot is not None:

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/axis.py in get_majorticklabels(self)    1155     def get_majorticklabels(self):    1156         'Return a list of Text instances for the major ticklabels'
-> 1157         ticks = self.get_major_ticks()    1158         labels1 = [tick.label1 for tick in ticks if tick.label1On]    1159         labels2 = [tick.label2 for tick in ticks if tick.label2On]

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/axis.py in get_major_ticks(self, numticks)    1284         'get the tick instances; grow as necessary'    1285         if numticks is None:
-> 1286             numticks = len(self.get_major_locator()())    1287         if len(self.majorTicks) < numticks:    1288             # update the new tick label properties from the old

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in __call__(self)
    863     def __call__(self):
    864         'Return the locations of the ticks'
--> 865         self.refresh()
    866         return self._locator()
    867 

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in refresh(self)
    880     def refresh(self):
    881         'Refresh internal information based on current limits.'
--> 882         dmin, dmax = self.viewlim_to_dt()
    883         self._locator = self.get_locator(dmin, dmax)
    884 

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
    624     def viewlim_to_dt(self):
    625         vmin, vmax = self.axis.get_view_interval()
--> 626         return num2date(vmin, self.tz), num2date(vmax, self.tz)
    627 
    628     def _get_unit(self):

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in num2date(x, tz)
    343         tz = _get_rc_timezone()
    344     if not cbook.iterable(x):
--> 345         return _from_ordinalf(x, tz)
    346     else:
    347         x = np.asarray(x)

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
    223         tz = _get_rc_timezone()
    224     ix = int(x)
--> 225     dt = datetime.datetime.fromordinal(ix)
    226     remainder = float(x) - ix
    227     hour, remainder = divmod(24 * remainder, 1)

ValueError: ordinal must be >= 1
weather_Maru 2012['Temp(摄氏度)]。绘图(figsize=(15,5))
--------------------------------------------------------------------------- 
()中的ValueError回溯(最近一次调用)
---->2012年3月1日天气[Temp(摄氏度)]。图(figsize=(15,5))
/plot_系列中的home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py(数据、种类、ax、figsize、使用索引、标题、网格、图例、样式、logx、logy、loglog、xticks、yticks、xlim、ylim、rot、fontsize、colormap、表格、yerr、xerr、label、secondary___y、**kwds)2486;=yerr=yerr,2487标签=标签,次要y=次要y,
->2488**科威特第纳尔)24892490
/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in_plot(数据,x,y,子地块,ax,kind,**kwds)2292 plot_obj=klass(数据,子地块=子地块,ax=ax,kind=kind,**kwds)2293
->2294绘图对象生成()2295绘图对象绘制()2296返回绘图对象结果
/生成(self)中的home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py
922自成传奇()
923自身(后)绘图(逻辑)
-->924自我装饰子图()
925
926 def参数调整(自):
/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in\u装饰子地块(self)1052 ax.set\u xticklabels(xticklabels)1053 self.\u应用轴属性(ax.xaxis,rot=self.rot,
->1054 fontsize=self.fontsize)1055 elif self.orientation==“水平”:1056如果self.\u需要设置索引:
/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in_-apply_-axis_属性(self,axis,rot,fontsize)1061 1062 def_-apply_-axis_属性(self,axis,rot=None,fontsize=None):
->1063 labels=axis.get_majorticklabels()+axis.get_minorticklabels()1064用于标签中的标签:1065如果rot不是None:
/get_majorticklabels(self)1155 def get_majorticklabels(self):1156'返回主要标签的文本实例列表'
->1157 ticks=self.get_major_ticks()1158 label1=[tick.label1表示tick.label1表示tick.label1On]1159 label2=[tick.label2表示tick.label2表示tick.label2表示tick.label2On]
/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/axis.py in get_major_ticks(self,numticks)1284’get the tick实例;如果numticks为None,则根据需要增长'1285:
->1286 numticks=len(self.get_major_locator())1287如果len(self.majorTicks)865 self.refresh()
866返回自我定位器()
867
/刷新中的home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py(self)
880 def刷新(自):
881“根据当前限制刷新内部信息。”
-->882 dmin,dmax=self.viewlim_to_dt()
883 self.\u locator=self.get\u locator(dmin,dmax)
884
/viewlim____dt(self)中的home/vagrant/ANACONA3/lib/python3.4/site-packages/matplotlib/dates.py
624 def viewlim_至_dt(自):
625 vmin,vmax=self.axis.get_view_interval()
-->626返回num2日期(vmin,self.tz),num2日期(vmax,self.tz)
627
628 def_获取_装置(自身):
/num2date(x,tz)中的home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py
343 tz=\u get\u rc\u时区()
344如果不是cbook.iterable(x):
-->345依次从左(x,tz)返回
346其他:
347 x=np.asarray(x)
/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in_from_ordinalf(x,tz)
223 tz=\u get\u rc\u时区()
224 ix=int(x)
-->225 dt=datetime.datetime.fromordinal(ix)
226余数=浮动(x)-ix
227小时,余数=divmod(24*余数,1)
ValueError:序号必须大于等于1
这是什么意思


如何修复此问题?

这是pandas中的一个错误:0.18.1,在0.19.2中修复,例如运行
conda upgrade pandas
即使使用当前的pandas 0.20.3,我在ipython中也会遇到此错误

追溯到之前运行了一个脚本,该脚本使用不同的索引保存了一个图形,但没有执行
plt.show()
,因为该图形已经保存,我不需要查看它


正如@NOTT101所暗示的,在显示下一个图之前强制
plt.close('all')
可以解决这个问题。无论如何,在脚本结束时可能是一个很好的做法。

由于某些原因,您可能会因为日期而出现错误。如果不查看数据,就很难确定。也许你可以尝试重置索引,强制列使用
pd.to_datetime
,然后再次将其设置为索引?它已经是一个时间序列weather\u mar2012.index[2012-03-01 00:00:00,…,2012-03-31 23:00:00]长度:744,频率:无,时区:无我也看到了这个。。。在重置和删除索引后,也使用相同的数据帧获取它,因此我认为这与index.aa无关,关闭现有的打开绘图可以解决问题。可能是因为我试图用不一致的索引绘制两个不同的数据帧。嗯……不知道这是不是一个bug——Noot101救了我。没有巴解组织
weather_mar2012['Temp (°C)'].plot(figsize=(15, 5))



--------------------------------------------------------------------------- 
ValueError                                Traceback (most recent call last) <ipython-input-31-21c79ba7d5ef> in <module>()
----> 1 weather_mar2012['Temp (°C)'].plot(figsize=(15, 5))

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)    2486                  yerr=yerr, xerr=xerr,    2487                  label=label, secondary_y=secondary_y,
-> 2488                  **kwds)    2489     2490 

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)    2292         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)    2293 
-> 2294     plot_obj.generate()    2295     plot_obj.draw()    2296     return plot_obj.result

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in generate(self)
    922         self._make_legend()
    923         self._post_plot_logic()
--> 924         self._adorn_subplots()
    925 
    926     def _args_adjust(self):

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _adorn_subplots(self)    1052                     ax.set_xticklabels(xticklabels)    1053                 self._apply_axis_properties(ax.xaxis, rot=self.rot,
-> 1054                                            fontsize=self.fontsize)    1055             elif self.orientation == 'horizontal':    1056                 if self._need_to_set_index:

/home/vagrant/anaconda3/lib/python3.4/site-packages/pandas/tools/plotting.py in _apply_axis_properties(self, axis, rot, fontsize)    1061     1062  def _apply_axis_properties(self, axis, rot=None, fontsize=None):
-> 1063         labels = axis.get_majorticklabels() + axis.get_minorticklabels()    1064         for label in labels:    1065             if rot is not None:

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/axis.py in get_majorticklabels(self)    1155     def get_majorticklabels(self):    1156         'Return a list of Text instances for the major ticklabels'
-> 1157         ticks = self.get_major_ticks()    1158         labels1 = [tick.label1 for tick in ticks if tick.label1On]    1159         labels2 = [tick.label2 for tick in ticks if tick.label2On]

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/axis.py in get_major_ticks(self, numticks)    1284         'get the tick instances; grow as necessary'    1285         if numticks is None:
-> 1286             numticks = len(self.get_major_locator()())    1287         if len(self.majorTicks) < numticks:    1288             # update the new tick label properties from the old

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in __call__(self)
    863     def __call__(self):
    864         'Return the locations of the ticks'
--> 865         self.refresh()
    866         return self._locator()
    867 

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in refresh(self)
    880     def refresh(self):
    881         'Refresh internal information based on current limits.'
--> 882         dmin, dmax = self.viewlim_to_dt()
    883         self._locator = self.get_locator(dmin, dmax)
    884 

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
    624     def viewlim_to_dt(self):
    625         vmin, vmax = self.axis.get_view_interval()
--> 626         return num2date(vmin, self.tz), num2date(vmax, self.tz)
    627 
    628     def _get_unit(self):

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in num2date(x, tz)
    343         tz = _get_rc_timezone()
    344     if not cbook.iterable(x):
--> 345         return _from_ordinalf(x, tz)
    346     else:
    347         x = np.asarray(x)

/home/vagrant/anaconda3/lib/python3.4/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
    223         tz = _get_rc_timezone()
    224     ix = int(x)
--> 225     dt = datetime.datetime.fromordinal(ix)
    226     remainder = float(x) - ix
    227     hour, remainder = divmod(24 * remainder, 1)

ValueError: ordinal must be >= 1