我想画一个有前途的公司的烛台。我的代码如下:
import numpy as np
import pandas as pd
from pandas_datareader import data as pdr
import fix_yahoo_finance as yf
yf.pdr_override()
#My python 3.6 seem in trouble using pandas_datareader directly,so I install a makeup
gree=pdr.get_data_yahoo('000651.SZ', start='2000-01-01',end='2018-04-30')
gree.info()
gree['Close'].plot(grid=True,figsize=(8,5))
gree['42d']=pd.rolling(gree['Close'],window=42).mean()
gree['42d']=np.round(pd.rolling(gree['Close'],window=42).mean(),2)
gree['252d']=np.round(pd.rolling_mean(gree['Close'],window=252),2)
gree[['Close','42d','252d']].tail()
我遇到了一个问题: AttributeError:模块“ pandas”没有属性“ rolling”。 尽管我已经阅读了几乎所有可用的答案,但我不知道如何解决。可以帮我一个忙吗? :D
答案 0 :(得分:0)
我认为需要Series.rolling
,请检查docs:
所以改变:
gree['42d']=pd.rolling(gree['Close'],window=42).mean()
gree['42d']=np.round(pd.rolling(gree['Close'],window=42).mean(),2)
gree['252d']=np.round(pd.rolling_mean(gree['Close'],window=252),2)
收件人:
gree['42d'] = gree['Close'].rolling(window=42).mean().round(2)
gree['252d'] = gree['Close'].rolling(window=252).mean().round(2)
或者如果使用熊猫波纹管0.18.0
:
gree['42d'] = pd.rolling_mean(gree['Close'],window=42)