首页 > 解决方案 > 如何在多索引数据帧上使用 Talib 计算随机 RSI?

问题描述

我一直在尝试使用“groupby”符号计算多索引数据帧上的随机 RSI,然后调用内联函数。以下是代码:

df['fastk'],df['fastd'] = df.groupby('Symbol')['Close'].apply(lambda y: talib.STOCHRSI(y, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0))

错误是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jafre\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2519, in __setitem__
    self._set_item(key, value)
  File "C:\Users\jafre\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2585, in _set_item
    value = self._sanitize_column(key, value)
  File "C:\Users\jafre\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2760, in _sanitize_column
    value = _sanitize_index(value, self.index, copy=False)
  File "C:\Users\jafre\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 3121, in _sanitize_index
    raise ValueError('Length of values does not match length of ' 'index')
ValueError: Length of values does not match length of index

有人可以帮助更改代码吗?

标签: pandas-groupbymulti-indexta-lib

解决方案


推荐阅读