pandas_select.label.AnyOf

class AnyOf(values, axis='columns', level=None)[source]

Select labels from a list.

The labels are sorted by the order they appear in the DataFrame.

AnyOf is similar to pandas.Series.isin().

Parameters
  • values (single label or list-like) – Index or column labels to select

  • 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 a IndexError will be raised.

Notes

AnyOf is similar to pandas.Series.isin().

Examples

>>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}, index=["a", "b"])
>>> df
   A  B
a  1  3
b  2  4
>>> df[AnyOf(["B", "A", "invalid"])]
   A  B
a  1  3
b  2  4
>>> df.loc[AnyOf("b", axis="index")]
   A  B
b  2  4