2

Wes McKinney の「Python for Data Analysis を調べていて、10 章の最後で説明されている pandas の移動ウィンドウ関数で問題が発生しました。

問題は、'rolling-mean' およびその他の 'rolling_' 関数が、必要な整数の TypeErrors でエラーになることです。これは、Python 2.7.3 および pandas 0.12.0 でのみ発生します。別のバージョンの Python に変更すると、これが修正されるようです。発生したエラーは pandas ライブラリに表示されます。

誰かがこの問題を見たことがありますか、それとも再現できますか?

私のPythonバージョンをアップグレードする代わりに、簡単な修正があるかどうか誰か知っていますか?

次のようにコーディングしてトレースバックします。

Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import scipy as sp
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> from pandas import Series, DataFrame
>>> 
>>> close_px_all = pd.read_csv('ch09/stock_px.csv', parse_dates=True, index_col=0)
>>> close_px = close_px_all[['AAPL', 'MSFT', 'XOM']]
>>> close_px = close_px.resample('B', fill_method='ffill')
>>> 
>>> close_px['AAPL'].plot()
<matplotlib.axes.AxesSubplot object at 0x9ddd46c>
>>> pd.rolling_mean(close_px['AAPL'], 250).plot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.py", line 1730, in plot_series
    plot_obj.generate()
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.py", line 856, in generate
    self._make_plot()
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.py", line 1240, in _make_plot
    self._make_ts_plot(data, **self.kwds)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.py", line 1311, in _make_ts_plot
    _plot(data, 0, ax, label, self.style, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.py", line 1295, in _plot
    style=style, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tseries/plotting.py", line 77, in tsplot
    lines = plotf(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py", line 4137, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py", line 317, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py", line 295, in _plot_args
    x, y = self._xy_from_xy(x, y)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py", line 214, in _xy_from_xy
    by = self.axes.yaxis.update_units(y)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1336, in update_units
    converter = munits.registry.get_converter(data)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/units.py", line 137, in get_converter
    xravel = x.ravel()
  File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 4025, in ravel
    r._mask = ndarray.ravel(self._mask).reshape(r.shape)
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/series.py", line 981, in reshape
    return ndarray.reshape(self, newshape, order)
TypeError: an integer is required
4

1 に答える 1