“"ValueError:索引包含重复的条目,无法重塑" pandas 数据读取器 [英] "ValueError: Index contains duplicate entries, cannot reshape" Pandas DataReader

查看:79
本文介绍了“"ValueError:索引包含重复的条目,无法重塑" pandas 数据读取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从Yahoo读取"AAPL"符号历史数据

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

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

我可以从Yahoo读取"GE"符号历史数据

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

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

我可以从Yahoo中读取"BTC-USD"符号的历史数据

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

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

我可以从Yahoo中读取"AAPL","GE"符号的历史数据

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

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

我无法同时从Yahoo中读取"AAPL","BTC-USD"符号的历史数据

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

为什么?

谢谢

推荐答案

进入调试模式,并对self.index执行value_counts(). 这样,您就会看到哪个日期和哪个符号导致了该问题.

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.

单独下载BTC-USD时,不会出现此问题,因为pandas-datareader正在堆积,并且所有符号都已成为列名.当只有一个符号时,这不是问题.但是,如果有很多符号,则在堆叠时会导致错误.

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.

在12月19日和12月6日,我使用以下符号CBS,STI,VIAB遇到了同样的问题.

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

这篇关于“"ValueError:索引包含重复的条目,无法重塑" pandas 数据读取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆