pandas-groupby - 如何在多索引数据帧上使用 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
有人可以帮助更改代码吗?
解决方案
推荐阅读
- solr - how to resolve solr create aliase error URI is too large?
- azure-devops - Azure DevOps Pipeline test showing partially succeeded
- python - 从给定列表中查找包含 int 值的缺失字符串
- python - 列值的两次出现并更新另一列的值
- typescript - 将 Testcafe 与 Appium 一起使用
- algorithm - making clusters dynamically so that if few data points are removed other clusters remain unaffected
- c# - How can I post data in database by showing data from another table in Dropdownlist
- reactjs - 如何在单击按钮时切换字段?
- python - 执行roll命令后删除作者信息
- quarkus - Quarkus : Converting existing spring application