gpt4 book ai didi

python-3.x - Python - 属性错误 : module 'pandas' has no attribute 'ewm'

转载 作者:行者123 更新时间:2023-12-05 00:40:00 36 4
gpt4 key购买 nike

我正在尝试运行以下代码,但出现错误。

line 43, in <module> ups_avg = pd.ewm(ups, span=RSI_N)[-1] 
AttributeError: module 'pandas' has no attribute 'ewm

我正在使用最新的 pandas 模块。请问43号线怎么修?谢谢

from binance.client import Client    
import numpy as np
import pandas as pd
import smtplib
import time
import yaml

CONFIG = yaml.load(open('./CONFIG.yml'))
API_KEY = CONFIG['binance_api']['key']
API_SECRET = CONFIG['binance_api']['secret']
user = CONFIG['gmail']['user']
passwd = CONFIG['gmail']['password']

client = Client(API_KEY, API_SECRET)

# against ETH
SYMBOLS = ('ADA', 'ADX', 'BAT', 'BCC', 'DASH', 'EOS', 'IOTA',

        'LTC', 'NEO', 'OMG', 'STORJ', 'XLM', 'NANO', 'XRP', 'XVG', 'ZEC')
RSI_N = 14
RSI_THRESHOLD = 8
RUN_INTERVAL_MINS = 30

def send_email(rsi_values):
    if len(rsi_values) > 0:
        message = '\n'.join('{0:>8} {1:.2f}'.format(symbol, rsi) for (symbol, rsi) in rsi_values)
        email_text = 'From: {0}\nTo: {1}\nSubject: Stock Recommendations\n\n{2}'.format(user, user, message)

        try:
            server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
            server.ehlo()
            server.login(user, passwd)
            server.sendmail(user, user, email_text)
            server.close()
        except:
            pass

while True:
    rsi_values = []
    for SYMBOL in SYMBOLS:
        klines = client.get_historical_klines(SYMBOL + 'ETH', Client.KLINE_INTERVAL_30MINUTE, '{} hours ago UTC'.format((RSI_N + 3) // 2))
        closings = np.asarray(klines, dtype=np.float)[-RSI_N - 1:, 4]
        diffs = np.diff(closings)
        ups = diffs.clip(min=0)
        downs = diffs.clip(max=0)
        ups_avg = pd.ewma(ups, span=RSI_N)[-1]
        downs_avg = -pd.ewma(downs, span=RSI_N)[-1]
        rs = ups_avg / downs_avg
        rsi = 100 - 100 / (1 + rs)
        rsi_values.append((SYMBOL, rsi))

    print('\n'.join('{0:>8} {1:.2f}'.format(symbol, rsi) for (symbol, rsi) in rsi_values))
    rsi_values = list(filter(lambda x: x[1] < RSI_THRESHOLD, rsi_values))
    send_email(rsi_values)
    time.sleep(60 * RUN_INTERVAL_MINS)

最佳答案

使用对象 dataframe.ewm().mean()

ups.ewm(span=RSI_N)
Eg.
df = DataFrame({'B': [0, 1, 2, np.nan, 4]})
df.ewm(com=0.5).mean()

关于python-3.x - Python - 属性错误 : module 'pandas' has no attribute 'ewm' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51690241/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com