I want to pull ticker data from the all the sp500 stocks from yahoo.
I saved the sp500 ticker symbols into a list from a local csv file that I made.
When when I run the following code, I get the:
ValueError 'Index contains duplicate entries, cannot reshape'
However, I noticed that this problem doesn't seem to occur with shorter stock lists but can't figure why; some help would be fully appreciated.
import pandas as pd
import numpy as np
from pandas_datareader import data
from statsmodels.tsa.stattools import coint
import matplotlib.pyplot as plt
from pyfinance.ols import PandasRollingOLS
sp500=pd.read_csv('sp500 stocks list.csv')
sp500_list=[]
for i in sp500:
sp500_list.append(i)
dataframe=data.DataReader(sp500_list, 'yahoo',start='2020/01/01')
print(dataframe)
I have tried dataframe = dataframe.drop_duplicates(sp500_list)
however i still gives me the same ValueError