pandas_select.label.LabelMask¶
-
class
LabelMask
(cond, axis='columns', level=None, **kwargs)[source]¶ Select labels where the condition is True.
- Parameters
cond (bool Series/DataFrame, array-like, or callable) – Select labels where cond is True. If cond is a callable, it is computed on the
Index
and should return a boolean array.axis (default 'columns') – Axis along which the function is applied, {0 or ‘index’, 1 or ‘columns’}
level (optional) – Either the integer position of the level or its name. It should only be set if
axis
targets a MultiIndex, otherwise aIndexError
will be raised.kwargs – If
cond
is acallable()
, additional keyword arguments passed to it.
Notes
If applied to a
MultiIndex
withlevel=None
, all the levels will be tested.Examples
>>> df = pd.DataFrame({"A": [1], "B": [1]}) >>> df A B 0 1 1 >>> df[LabelMask([True, False])] A 0 1 >>> df[LabelMask(lambda x: x == "A")] A 0 1