简体   繁体   中英

pandas numpy.ndarray object has no attribute

I changed pd.ewm into pd.DataFrame.ewm just like others says (The original was pd.ewm(ups.span=RSI_N)[-1] ). But it follows me an another problem. What did I did wrong? Does anybody know what is happening?

I've edited into full error message

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

API_KEY = 'jHH6LNaSsdenA6xdJLRN9LVngY9KgrZ4dTzdk8685D6oquaVovY1PSuHgeQRCal5'
API_SECRET = 'DzJjJFkjppeSPQYBZg66Y2taIDr25ENfkI0G0SrxsqePYtdJX9cnxqdAHF0I8ocjS'
user = 'shinadfjinseub@gmail.com'
passwd = 'asdfaasdf!!'

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.DataFrame.ewm(ups, span=RSI_N).mean()
        downs_avg = -pd.DataFrame.ewm(downs, span=RSI_N).mean()
        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)

error:

      Traceback (most recent call last):
  File "C:\Users\심현규\PycharmProjects\FINALPROJECT\autowork.py", line 43, in <module>
    ups_avg = pd.DataFrame.ewm(ups, span=RSI_N).mean()
  File "C:\Users\심현규\PycharmProjects\FINALPROJECT\venv\lib\site-packages\pandas\core\generic.py", line 11282, i
n ewm
    axis = self._get_axis_number(axis)
AttributeError: 'numpy.ndarray' object has no attribute '_get_axis_number'

You are never actually converting ups to a DataFrame. The DataFrame.ewm() method should be applied to an instance of pandas dataframe or a pandas Series (as per Mustafa's comment).

So this should hopefully fix things:

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)
        ups = pd.DataFrame(ups)   # Convert to a dataframe    
        downs = diffs.clip(max=0)
        ups_avg = ups.ewm(span=RSI_N).mean()   # Now perform ewm on the dataframe

Hope this helps. There might be similar issues with other variables too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM