【问题标题】:Ta-lib and pandas series not working with pythonTa-lib 和 pandas 系列不适用于 python
【发布时间】:2018-06-02 15:40:57
【问题描述】:

我是编码新手,所以请耐心等待我;) 这是我的代码不起作用,我尝试了几个小时来解决它,但每次我都遇到另一个错误。

import pandas as pd
import numpy as np
import talib.abstract as ta


dfBTCUSD_1h = pd.read_csv('Bitfinex_BTCUSD_1h.csv', skiprows=1)
dfBTCUSD_1h.sort_values(by='Date') # This now sorts in date order


open = dfBTCUSD_1h.iloc[:,2]
high = dfBTCUSD_1h.iloc[:,3]
low  = dfBTCUSD_1h.iloc[:,4]
close =dfBTCUSD_1h.iloc[:,5]

short_ema = ta.EMA(close,timeperiod=10)

TypeError: cannot convert the series to <class 'int'>

如何将 pandas 系列编辑为 ta-lib 的工作文件?

最好的问候

【问题讨论】:

  • 那是 TypeError 的全部吗?我认为这不太可能。你能发布完整的错误信息吗?您还可以隔离给您错误的行吗?在 IDE 中使用断点,或者注释掉 OHLC 部分并检查错误是否仍然存在,以便您可以找出导致错误的行
  • 文件“C:\Users\maxi\Annaconda3\lib\site-packages\pandas\core\series.py”,第 112 行,包装“{0}”.format(str(converter ))) TypeError: cannot convert the series to error is the last line
  • 你能打印变量'close'的数据类型吗?
  • 它是 pandas.core.series 模块的系列对象

标签: python pandas dataframe series ta-lib


【解决方案1】:

不要将code 提供给ta.EMA,而是执行以下操作:

short_ema = ta.EMA(close.astype(float),timeperiod=10)

Talib 函数通常将 dtype 浮点数的 numpy 数组作为输入

【讨论】:

  • 是的,我想我必须转换它。我试过了,但我在包装器“{0}”中收到另一个错误文件“C:\Users\maxi\Annaconda3\lib\site-packages\pandas\core\series.py”,第 112 行。格式(str(转换器)))类型错误:无法将系列转换为
  • 你能帮我打印一下'close'吗?
  • 这只是其中的一小部分。 5629 4845.90 5630 4794.90 5631 4745.00 5632 4715.30 5633 4649.90 5634 4643.00 5635 4667.00 5636 4617.20 5637 4595.50 5638 4603.00 5639 4594.90 5640 4585.70 Name: Close, Length: 5641, dtype: float64
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-29
  • 2020-05-05
  • 1970-01-01
  • 2016-05-22
  • 2021-08-30
相关资源
最近更新 更多