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

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

问题描述

我可以阅读AAPL"来自雅虎的符号历史数据

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

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

我可以阅读GE"来自雅虎的符号历史数据

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

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

我可以阅读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']

我可以阅读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']

我无法同时读取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.

我在 19 年 12 月 4 日和 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天全站免登陆