I've tried various variations of code including trying to reset_index() because maybe there is a multiindex that is causing the error. If you see the print out below you will notice the 'Symbol' index. I'm not sure how to delete that and whether that will fix the error or not.
tickers = ['AAPL', 'BAC']
prices_list = []
for ticker in tickers:
try:
prices = dr.DataReader(ticker,'morningstar','01/01/2017')['Close']
prices = pd.DataFrame(prices)
prices.columns = [ticker]
prices_list.append(prices)
except:
pass
prices_df = pd.concat(prices_list,axis=1,copy=False)
#prices_df.sort_index(inplace=True)
print(prices_df.head())
Results--->
AAPL BAC
Symbol Date
AAPL 2017-01-02 115.82 NaN
2017-01-03 116.15 NaN
2017-01-04 116.02 NaN
2017-01-05 116.61 NaN
2017-01-06 117.91 NaN
I'm actually using this basic code to fix this error. I'm pulling data online for the S&P 500.
I think the error is occurring during concatenation, but I'm not sure how to fix that. If you print out prices_list the data is a list of dataframes that includes all the numbers so it's not a problem with the source.