0

I'm trying to run the code below and I'm getting a weird error that says 'cannot import name 'is_list_like''. I tried Googling for a solution, but I can't figure it out.

import numpy as np
import pandas as pd
import pandas_datareader as web
#import matplotlib.pyplot as plt

symbols = ['BIIB','CELG','GILD','AMGN','REGN','ILMN','VRTX','ALXN','MYL']
noa = len(symbols)
data = pd.DataFrame()
for sym in symbols:
    data[sym] = web.DataReader(sym, data_source='yahoo',end='2015-05-01')['Adj Close']
data.columns = symbols
(data / data.ix[0] * 100).plot(figsize=(8, 5))
rets = np.log(data / data.shift(1))
rets.mean() * 252
rets.cov() * 252

weights = np.random.random(noa)
weights /= np.sum(weights)
print(weights)

Can someone here shed some light on this? Thanks.

ASH
  • 15,523
  • 6
  • 50
  • 116
  • please could you post the full traceback ? – PRMoureu Jun 03 '18 at 12:16
  • I saw that link before posting, but I'm not sure what the final solution was. I just tried this: import pandas_datareader as web I'm getting the same error – ASH Jun 03 '18 at 12:32
  • have you tried the workaround in this comment : https://stackoverflow.com/questions/50394873/import-pandas-datareader-gives-importerror-cannot-import-name-is-list-like#comment87850508_50415484 – PRMoureu Jun 03 '18 at 12:41
  • I added this: from pandas.api.types import is_list_like Then I tried this: for sym in symbols: data[sym] = is_list_like.DataReader(sym, data_source='yahoo',end='2015-05-01')['Adj Close'] data.columns = symbols Still getting the same error. – ASH Jun 03 '18 at 13:03
  • 3
    the comment proposed another trick : `pd.core.common.is_list_like = pd.api.types.is_list_like` before `import pandas_datareader as web` – PRMoureu Jun 03 '18 at 13:47
  • That works! Thanks!! – ASH Jun 03 '18 at 14:44

0 Answers0