Pandas Depreciated Package,试图更新

时间:2017-11-22 15:44:33

标签: python python-3.x pandas

如何更新此折旧包裹?

代码:

def M_A_C_D( df, f, s):
   fast_ema = pd.ewma( df['Close'], span=f)
   slow_ema = pd.ewma( df['Close'], span=s)
   macd = fast_ema - slow_ema
   return slow_ema

错误

FutureWarning:pd.ewm_mean已弃用于系列,将在a中删除    未来版本,替换为    Series.ewm(跨度= 12,min_periods = 0,调整=真,ignore_na =假).mean()

我的尝试

def M_A_C_D( df, f, s):
  fast_ema = df['Close'].ewm(span=f)
  slow_ema = df['Close'].ewm(span=s)
  macd = fast_ema - slow_ema
  return slow_ema

错误

TypeError:不支持的操作数类型 - :'EWM'和'EWM'

我的第二次尝试

def M_A_C_D( df, f, s):
  fast_ema = df['Close'].ewm(span=f).mean()
  slow_ema = df['Close'].ewm(span=s).mean()
  macd = fast_ema - slow_ema
  return slow_ema

消息:我不知道为什么它会给我这个。我想要macd-fast_ema-slow_ema?我很困惑:(

def MACD(df,period1,period2,periodSignal): EMA1 = 
   pd.DataFrame.ewm(df,span=period1).mean() EMA2 = 
   pd.DataFrame.ewm(df,span=period2).mean() MACD = EMA1-EMA2
   Signal = pd.DataFrame.ewm(MACD,periodSignal).mean()

   Histogram = MACD-Signal

   return Histogram

0 个答案:

没有答案