I am trying to unstack a multi-index with pandas and I am keep getting:
ValueError: Index contains duplicate entries, cannot reshape
Given a dataset with four columns:
- id (string)
- date (string)
- location (string)
- value (float)
I first set a three-level multi-index:
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
Then I try to unstack the location:
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
What is going on here?