Closed
Description
In [1]:
import pandas as pd
import numpy as np
print pd.__version__
a = np.linspace(0, 10, 11)
idx = [('test1', i) for i in range(5)]
idx.extend([('test2', i) for i in range(6)])
idx = pd.MultiIndex.from_tuples(idx)
0.15.2-80-ge69deae
In [2]:
a = pd.Series(a, idx)
a
Out[2]:
test1 0 0
1 1
2 2
3 3
4 4
test2 0 5
1 6
2 7
3 8
4 9
5 10
dtype: float64
In [3]:
a.loc[('test1', 2)] = 13
a
Out[3]:
test1 0 0
1 1
2 13
3 3
4 4
test2 0 5
1 6
2 7
3 8
4 9
5 10
dtype: float64
In [4]:
a.loc[('test', 17)] = 13
---------------------------------------------------------------------------
IndexingError Traceback (most recent call last)
<ipython-input-4-157acf13152f> in <module>()
----> 1 a.loc[('test', 17)] = 13
/home/federico/Python_Libraries/pandas/pandas/core/indexing.pyc in __setitem__(self, key, value)
114 if len(key) > self.ndim:
115 raise IndexingError('only tuples of length <= %d supported' %
--> 116 self.ndim)
117 indexer = self._convert_tuple(key, is_setter=True)
118 else:
IndexingError: only tuples of length <= 1 supported
In [5]:
a.ix[('test', 17)] = 13
---------------------------------------------------------------------------
IndexingError Traceback (most recent call last)
<ipython-input-5-89467846f8af> in <module>()
----> 1 a.ix[('test', 17)] = 13
/home/federico/Python_Libraries/pandas/pandas/core/indexing.pyc in __setitem__(self, key, value)
114 if len(key) > self.ndim:
115 raise IndexingError('only tuples of length <= %d supported' %
--> 116 self.ndim)
117 indexer = self._convert_tuple(key, is_setter=True)
118 else:
IndexingError: only tuples of length <= 1 supported
Somehow - the enlarging fails. Any clue how to get it to work? I have also noticed that the 'fast' indexing methods, iat and at fail with DataFrames that are multi indexed.