pythonpandasapiyahoopandas-datareader

"ValueError: Index contains duplicate entries, cannot reshape" Pandas DataReader


I can read the "AAPL" symbol historical data from yahoo

dfcomp3 = web.DataReader(["AAPL"],'yahoo',start=start,end=end)['Adj Close']

I can read the "GE" symbol historical data from yahoo

dfcomp3 = web.DataReader(["AAPL"],'yahoo',start=start,end=end)['Adj Close']

I can read the "BTC-USD" symbol historical data from yahoo

dfcomp3 = web.DataReader(["BTC-USD"],'yahoo',start=start,end=end)['Adj Close']

I can read both "AAPL","GE" symbols historical data from yahoo

dfcomp7 = web.DataReader(["GE", "AAPL"],'yahoo',start=start,end=end)['Adj Close']

I can't read both "AAPL","BTC-USD" symbols historical data from yahoo

dfcomp7 = web.DataReader(["BTC-USD", "AAPL"],'yahoo',start=start,end=end)['Adj Close']

    ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-58-0cbbb3aa9346> in <module>()
----> 1 dfcomp7 = web.DataReader(["BTC-USD", "AAPL" ],'yahoo',start=start,end=end)['Adj Close']

7 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/reshape/reshape.py in _make_selectors(self)
    164 
    165         if mask.sum() < len(self.index):
--> 166             raise ValueError('Index contains duplicate entries, '
    167                              'cannot reshape')
    168 

ValueError: Index contains duplicate entries, cannot reshape

Why?


Solution

  • go in debug mode and do an value_counts() on self.index. that way you will see which date with which symbol is creating the issue.

    when BTC-USD is downloaded by itself, it doesn't create this issue as pandas-datareader is unstacking and all symbols are becoming column names. Which is not a problem while there is just one symbol. However with many symbols it leads to an error while unstacking.

    I had same problems with following symbol CBS, STI, VIAB for the dates 4th Dec 19 and 6th Dec 19.