pandas_select.label.Exact

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

Select labels from a list, sorted by the order they appear in the list.

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.

Raises

ValueError: – If values contains duplicates.

Examples

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