Python numpy round function weird bug

I have the following code from a python book for finance. But the round function from numpy causes an error like "return round (decimals, out) TypeError: round () takes no more than 2 arguments (3 data)"

Does anyone know what I'm doing wrong?

import numpy as np
import pandas as pd
import pandas.io.data as web

sp500 = web.DataReader('^GSPC', data_source='yahoo',
                            start='1/1/2000', end='4/14/2014')
sp500.info()
sp500['Close'].plot(grid=True, figsize=(8, 5))

sp500['42d'] = np.round(pd.rolling_mean(sp500['Close'], window=42), 2)
+4
source share
1 answer

Based on the error message, it seems that numpy 1.11.0the rounding function looks like this:

try:
    round = a.round
except AttributeError:
    return _wrapit(a, 'round', decimals, out)
return round(decimals, out)

It looks like it pandas.Series.roundtakes only two arguments ( self, precision), but numpypasses it an additional argument out. Presumably this is either a bug or a change to the API in pandasor numpy.

, . - Series.round():

sp500['42d'] = pd.rolling_mean(sp500['Close'], window=42).round(2)

- numpy.round numpy:

sp500['42d'] = np.round(pd.rolling_mean(sp500['Close'], window=42).values, 2)

. , . . pandas github tracker, # 12644.

+3

All Articles