我正在尝试向数据框中添加几列 - 这是代码import import_ipynbimport talibimport numpyimport yfinance as yfimport datetime as dtimport timefrom datetime import datetime, timedelta import sqlite3import pandasimport numpy as npconn = sqlite3.connect('Strategy_RSI_MACD_Data.db')c = conn.cursor() c.execute("select distinct Stock from Universe")tickers = c.fetchall() for row in tickers: if row[0]: ticker_list.append(row[0]) stockdetails = yf.download( tickers = ticker_list, period = '6mo', interval = '1d', group_by = 'ticker', auto_adjust = False, prepost = False, threads = True, proxy = None )df_ta = pandas.DataFrame(data = stockdetails['Adj Close'], dtype=numpy.float64)stockdetails['RSI'] = df_ta.apply(lambda c: talib.RSI(c, timeperiod = 14))最后一行抛出此错误:ValueError:通过的项目数量错误 505,放置意味着 1我怎样才能解决这个问题?
2 回答
心有法竹
TA贡献1866条经验 获得超5个赞
我想到了!!- 我需要插入一个循环来遍历这些值:
for row in tickers:
c.execute("select [Adj Close] from StockData where Symbol = ? ", (row))
AdjClose = c.fetchall()
df_ta = pd.DataFrame(data = AdjClose, dtype=numpy.float64)
df_ta = df_ta.apply(lambda c: talib.RSI(c, timeperiod = 14))
HUX布斯
TA贡献1876条经验 获得超6个赞
您的 lambda 函数返回 505 个值,而您的赋值应该只有一个值。尝试将输出转换为列表 -
stockdetails['RSI'] = [df_ta.apply(lambda c: talib.RSI(c, timeperiod = 14))]
添加回答
举报
0/150
提交
取消