I would like to change the column names of the pd frame, but I find that the order of the columns changes after receiving the data. The code below identifies ETF symbol sectors and retrieves data from yahoo finance.
The problem is that as soon as I run the code, for example, “XLY” is no longer the first series in the data framework, so I can’t just run sec_perf.columns = ['Name1', 'Name2', etc. ] as Normally I would like, because it will not indicate columns correctly. What have I messed up here?
import pandas as pd
import pandas_datareader.data as web
import datetime as datetime
end = datetime.date.today()
secs = ['XLY', 'XLP', 'XLE',
'XLF', 'XLV', 'XLI',
'XLB', 'XLRE', 'XLK', 'XLU']
sec_perf = web.DataReader(secs, 'yahoo',
start = datetime.datetime(2016,12,31),
end = end)['Adj Close']
source
share