Reputation: 41
I've the following code:
ticker = ["IYR","IYZ","XLB","XLE","XLI","XLK","XLP","XLU","XLY","IYF"]
#downloading data and creating DFs
for ei in ticker:
vars()[ei] = yf.download(ei, start="2015-01-01", end="2020-10-21",auto_adjust=True)
#Iterate over DFs in order to rename columns
for ei in ticker:
vars()[ei].rename(columns={"Open":str(ei)+"_O", "High": str(ei)+"_H", "Low": str(ei)+"_L", "Close": str(ei)+"_C"})
But i don't know why, it does not rename. Any helps ? Thank you !!
Upvotes: 0
Views: 225
Reputation: 41
Solved:
for ei in ticker:
vars()[ei]=vars()[ei].rename(columns={"Open":str(ei)+"_O", "High": str(ei)+"_H", "Low": str(ei)+"_L", "Close": str(ei)+"_C"})
Upvotes: 1