用熊猫情节()获得"TypeError: float() argument must be a string or a number"



我将通过简单的熊猫教程。我正在尝试绘制由 dtype='datetime64[ns]' 索引的数据帧,但是,当我尝试绘制时,我假设 matplotlib 尝试将日期转换为浮点数,这引发了异常。

>>> df.index
DatetimeIndex(['2012-01-01', '2012-01-02', '2012-01-03', '2012-01-04',
           '2012-01-05', '2012-01-06', '2012-01-07', '2012-01-08',
           '2012-01-09', '2012-01-10',
           ...
           '2012-12-22', '2012-12-23', '2012-12-24', '2012-12-25',
           '2012-12-26', '2012-12-27', '2012-12-28', '2012-12-29',
           '2012-12-30', '2012-12-31'],
          dtype='datetime64[ns]', name=u'Date', length=366, freq=None)
>>> df.plot()
Traceback (most recent call last):
  ...
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/lines.py", line 676, in recache
    x = np.asarray(xconv, np.float_)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number

我做错了什么?

注意:我在这里遵循非常简单的教程:http://nbviewer.jupyter.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%201%20-%20Reading%20from%20a%20CSV.ipynb

本教程绘制的是 colmn 2 中的数字,而不是第 1 列中的日期:

日期

2012年01月01日 35

2012年01月02日 83

2012年01月03日 135

....

因此,您的

情节缺少某些内容,请再次检查您的输入...

相关内容

最新更新