0

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

S.I.J
  • 979
  • 1
  • 10
  • 22
Bemz
  • 129
  • 1
  • 16
  • Which line gives you the `ValueError`? Is it `read_csv`? – Simon Fraser Feb 25 '20 at 20:17
  • The code seems to be running fine and pulling data for all the 504 sp500 tickers , however it crashes before finishing. Its important to note that the code works perfectly for shorter ticker lists (below 100) – Bemz Feb 25 '20 at 21:25

0 Answers0