0

I'm new in Coding, so please be patient with me ;) This is my code that didn't work, I'm trying several hours to solve it, but every time I got another error.

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'>

How can I edit the pandas series to a working file for ta-lib?

best regards

Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
Cryptogear
  • 39
  • 7
  • Is that the TypeError in it's entirety? I think that's very unlikely. Could you post the full error message please? Could you also isolate the line that gives you the error? Use breakpoints in your IDE, or comment out the OHLC section and check if the error still persists so that you can single out the line causing the error – Abhay Nainan Jun 02 '18 at 18:43
  • File "C:\Users\maxi\Annaconda3\lib\site-packages\pandas\core\series.py", line 112, in wrapper "{0}".format(str(converter))) TypeError: cannot convert the series to the error is the last line – Cryptogear Jun 02 '18 at 19:03
  • Could you print the data type of the variable 'close' ? – Abhay Nainan Jun 02 '18 at 19:17
  • it's a series object of pandas.core.series module – Cryptogear Jun 02 '18 at 19:23

1 Answers1

0

Instead of supplying code to ta.EMA, do the following:

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

Talib functions usually take numpy arrays of dtype float as inputs

Abhay Nainan
  • 3,794
  • 2
  • 14
  • 14
  • yeah, i thought i have to convert it. I tried it, but i got another error File "C:\Users\maxi\Annaconda3\lib\site-packages\pandas\core\series.py", line 112, in wrapper "{0}".format(str(converter))) TypeError: cannot convert the series to – Cryptogear Jun 02 '18 at 19:32
  • Any chance you can print 'close' for me? – Abhay Nainan Jun 02 '18 at 19:34
  • this is only a short part of them. 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 – Cryptogear Jun 02 '18 at 19:41