import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
symbols = ["AAPL", "GLD", "TSLA", "GBL", "GOOGL"]
def compare_security(symbols):
start_date = "01-01-2019"
end_date = "01-12-2020"
dates = pd.date_range(start_date, end_date)
df1 = pd.DataFrame(index=dates)
df_SPY = pd.read_csv(
"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=SPY&apikey=XXXX&datatype=csv",
index_col="timestamp", usecols=["timestamp", "adjusted_close"], parse_dates=True, na_values=['nan'])
df_SPY = df_SPY.rename(columns={"adjusted_close": "SPY"})
df1 = df1.join(df_SPY, how="inner")
for symbol in symbols:
df_temp= pd.read_csv("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={}&apikey=XXXX&datatype=csv".format(symbol),
index_col = "timestamp", usecols = ["timestamp", "adjusted_close"], parse_dates=True, na_values=['nan'])
df_temp = df_temp.rename(columns={"adjusted_close":symbol})
df1 = df1.join(df_temp)
return df1
def test_run():
df = compare_security(symbols)
print(df)
df.plot()
plt.title(symbols)
plt.show()
if __name__ == "__main__":
test_run()
It reads the error "ValueError: Usecols do not match columns, columns expected but not found: ['timestamp', 'adjusted_close']"
However, I checked all the files the code would retrieve and all of them have the respective columns. Any clarification as to where I went wrong would be greatly appreciated.