MulSeries.mloc#

MulSeries.mloc#

Flexible hierachical indexing on the index dataframe.

The slicer can be a list or a dict. Check introduction to mloc ??? for detailed usage.

If a list is used, its length should be less than or equal to the columns length of the index dataframe. The hierarchical indexing order is from the leftmost column to the rightmost. Use ... as : in the list to select all elements in a column.

If a dict is used, its keys should be the column names of the index dataframe and its values the slicers on the columns. The hierachical indexing order is the insertion order of the keys in the dict. Although Python does not guanrantee the insertion order, it is preserved in most cases. Use the OrderedDict class if you are really concerned about it.

Examples#

List indexing:

>>> import pandas as pd
>>> import muldataframe as md
>>> index = pd.DataFrame([['a','b','c'],
                          [ 'g','b','f'],
                          [ 'b','g','h']],
                   columns=['x','y','y'])
>>> name = pd.Series(['a','b'],index=['e','f'],name='cc')
>>> ms = md.MulSeries([1,2,3],index=index,name=name)
>>> ms.mloc[[..., 'b']]
(2,)        e   a
            f   b
               cc
----------  ------
   x  y  y     cc
0  a  b  c  0   1
1  g  b  f  1   2
>>> ms.mloc[['g', ..., ['h','f']]]
2

Dictionary indexing:

>>> ms.mloc[{'y':['c','h'],'x':['b','a']}]
(2,)        e   a
            f   b
               cc
----------  ------
   x  y  y     cc
2  b  g  h  2   3
0  a  b  c  0   1

Note in the above example that if the index dataframe’s columns have duplicate names, use the last column for dict indexing.