Search code examples
pythonpandasdataframeyfinance

Unable to add values to a pandas DataFrame


I am trying to find the MACD(Moving Average Convergence Divergence) for a few stocks.I am using Pandas_ta, yfinance and pandas libraries. But When I am trying to add the Macd values to the dataframe I am getting this error:

IndexError: iloc cannot enlarge its target object

My code is :

import pandas as pd 
import pandas_ta as ta
import yfinance as yf
import datetime as dt
import matplotlib.pyplot as plt
start=dt.datetime.today()-dt.timedelta(365)
end=dt.datetime.today()
zscore=pd.DataFrame()
rsi=pd.DataFrame()
tickers=['2060.SR' , '2160.SR', '3002.SR', '4007.SR', '3005.SR', '3004.SR' , '2150.SR']
macd=pd.DataFrame()
for i in tickers:
  df=pd.DataFrame(yf.download(i, start=start, end=end, interval="1mo"))

  df.columns = map(str.lower, df.columns)    
  macd=df.ta.macd()
  

Can someone let me know where my mistake is and how to solve this error. thanks


Solution

  • df=df.merge(macd, on="Date")