Closed
Description
In [40]: columns = pd.MultiIndex.from_tuples([('a', 'foo'), ('a', 'bar'), ('b', 'hello'), ('b', 'world')], names=['lvl0', 'lvl1'])
In [41]: df = pd.DataFrame(np.random.randn(4, 4), columns=columns)
In [42]: df
Out[42]:
lvl0 a b
lvl1 foo bar hello world
0 2.560515 1.579242 0.727753 2.207781
1 -0.599632 0.254395 0.784745 0.340575
2 1.262004 0.409085 -0.229616 1.096679
3 1.637929 -0.694670 -0.356355 0.410580
In [43]: df.xs('a', level='lvl0', axis=1)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<...>
<...>/lib/python2.7/site-packages/pandas-0.11.0.dev_14a04dd-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in set_axis(self, axis, value)
831 if len(value) != len(cur_axis):
832 raise Exception('Length mismatch (%d vs %d)'
--> 833 % (len(value), len(cur_axis)))
834 self.axes[axis] = value
835
Exception: Length mismatch (2 vs 4)
In [44]: df.xs('a', axis=1)
Out[44]:
lvl1 foo bar
0 2.560515 1.579242
1 -0.599632 0.254395
2 1.262004 0.409085
3 1.637929 -0.694670
In [45]: pd.__version__
Out[45]: '0.11.0.dev-14a04dd'
[1227][i] uname -a
Linux xl-mec-03 2.6.18-308.11.1.el5 #1 SMP Fri Jun 15 15:41:53 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux