state color key key ohio green red colorado green with partial column indexing you can similarly select groups of columnsin [ ]frame['ohio'out[ ]color green red key key multiindex can be created by itself and then reusedthe columns in the above dataframe with level names could be created like thismultiindex from_arrays([['ohio''ohio''colorado']['green''red''green']]names=['state''color']reordering and sorting levels at times you will need to rearrange the order of the levels on an axis or sort the data by the values in one specific level the swaplevel takes two level numbers or names and returns new object with the levels interchanged (but the data is otherwise unaltered)in [ ]frame swaplevel('key ''key 'out[ ]state ohio colorado color green red green key key sortlevelon the other handsorts the data (stablyusing only the values in single level when swapping levelsit' not uncommon to also use sortlevel so that the result is lexicographically sortedin [ ]frame sortlevel( out[ ]state ohio colorado color green red green key key in [ ]frame swaplevel( sortlevel( out[ ]state ohio colorado color green red green key key hierarchical indexing www it-ebooks info