How can add ichimoku with the pandas_ta library in Python?

4.1k Views Asked by At

https://github.com/twopirllc/pandas-ta#overlap-33

import pandas_ta as ta
import pandas as pd


ichimoku = ta.ichimoku(df['high'], df['low'], df['close'])
df = pd.concat([df, ichimoku], axis=1)

TypeError: cannot concatenate object of type '<class 'tuple'>'; only Series and DataFrame objs are valid

1

There are 1 best solutions below

1
On BEST ANSWER

ichimoku returns two data frames. One returns the high and low indicators, and the other returns the look-ahead indicator, so combining them requires a data frame for each.

import yfinance as yf
import pandas_ta as ta
import pandas as pd

df = yf.download("AAPL", start="2021-01-01", end="2022-01-01")

ichimoku = ta.ichimoku(df['High'], df['Low'], df['Close'])
df = pd.concat([df, ichimoku[0], ichimoku[1]], axis=1)

df.head()
Open    High    Low     Close   Adj Close   Volume  ISA_9   ISB_26  ITS_9   IKS_26  ICS_26  ISA_9   ISB_26
2021-01-04  133.520004  133.610001  126.760002  129.410004  128.617111  143301900.0     NaN     NaN     NaN     NaN     135.389999  NaN     NaN
2021-01-05  128.889999  131.740005  128.429993  131.009995  130.207291  97664900.0      NaN     NaN     NaN     NaN     135.130005  NaN     NaN
2021-01-06  127.720001  131.050003  126.379997  126.599998  125.824326  155088000.0     NaN     NaN     NaN     NaN     135.369995  NaN     NaN
2021-01-07  128.360001  131.630005  127.860001  130.919998  130.117859  109578200.0     NaN     NaN     NaN     NaN     133.190002  NaN     NaN
2021-01-08  132.429993  132.630005  130.229996  132.050003  131.240936  105158200.0     NaN     NaN     NaN     NaN     130.839996  NaN     NaN