0

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

2
  • Do you get any errors? Did you try including inplace=True parameter? Commented Oct 27, 2020 at 16:03
  • Try replacing vars() with vars. Commented Oct 27, 2020 at 16:03

1 Answer 1

1

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"}) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.