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
Indexand 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
axistargets a MultiIndex, otherwise aIndexErrorwill be raised.kwargs – If
condis acallable(), additional keyword arguments passed to it.
Notes
If applied to a
MultiIndexwithlevel=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