最佳答案
我正试图解开一个有熊猫的多重索引,我不断得到:
ValueError: Index contains duplicate entries, cannot reshape
给定一个有四列的数据集:
我首先设置了一个三级多索引:
In [37]: e.set_index(['id', 'date', 'location'], inplace=True)
In [38]: e
Out[38]:
value
id date location
id1 2014-12-12 loc1 16.86
2014-12-11 loc1 17.18
2014-12-10 loc1 17.03
2014-12-09 loc1 17.28
然后我试着解开这个位置:
In [39]: e.unstack('location')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-39-bc1e237a0ed7> in <module>()
----> 1 e.unstack('location')
...
C:\Anaconda\envs\sandbox\lib\site-packages\pandas\core\reshape.pyc in _make_selectors(self)
143
144 if mask.sum() < len(self.index):
--> 145 raise ValueError('Index contains duplicate entries, '
146 'cannot reshape')
147
ValueError: Index contains duplicate entries, cannot reshape
这是怎么回事?