我有以下代碼:ticker = ["IYR","IYZ","XLB","XLE","XLI","XLK","XLP","XLU","XLY","IYF"]#downloading data and creating DFsfor 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 columnsfor ei in ticker: vars()[ei].rename(columns={"Open":str(ei)+"_O", "High": str(ei)+"_H", "Low": str(ei)+"_L", "Close": str(ei)+"_C"})但不知道為什么,它沒有重命名。有什么幫助嗎?謝謝 ??!
1 回答

jeck貓
TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
解決了:
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"})
添加回答
舉報(bào)
0/150
提交
取消