Pandas .join Not Working To Combine S&p500 Stock Data
I'm following the finance tutorials on PythonProgramming.net and have run into an issue when I try to combine several dataframes into one large dataframe. I created a function to d
Solution 1:
IIUC:
You don't want to use join
and you couldn't anyway if you start with an empty dataframe. Use pd.concat
instead:
main_df = pd.concat([main_df, df], axis=1)
However, I would recommend this to replace your whole process:
def read_file(ticker):
df = pd.read_csv('stock_dfs/{}.csv'.format(ticker)).set_index('Date')
return df.Close.rename(ticker)
with open ("sp500tickers.pickle", "rb") as f:
tickers = pickle.load(f)
main_df = pd.concat([read_file(t) for t in tickers], axis=1)
Post a Comment for "Pandas .join Not Working To Combine S&p500 Stock Data"