A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/docs/dev/user_guide/../reference/api/pandas.IndexSlice.html below:

pandas.IndexSlice — pandas 3.0.0.dev0+2231.g4f2aa4d2be documentation

pandas.IndexSlice#
pandas.IndexSlice = <pandas.core.indexing._IndexSlice object>#

Create an object to more easily perform multi-index slicing.

Notes

See Defined Levels for further info on slicing a MultiIndex.

Examples

>>> midx = pd.MultiIndex.from_product([["A0", "A1"], ["B0", "B1", "B2", "B3"]])
>>> columns = ["foo", "bar"]
>>> dfmi = pd.DataFrame(
...     np.arange(16).reshape((len(midx), len(columns))),
...     index=midx,
...     columns=columns,
... )

Using the default slice command:

>>> dfmi.loc[(slice(None), slice("B0", "B1")), :]
           foo  bar
    A0 B0    0    1
       B1    2    3
    A1 B0    8    9
       B1   10   11

Using the IndexSlice class for a more intuitive command:

>>> idx = pd.IndexSlice
>>> dfmi.loc[idx[:, "B0":"B1"], :]
           foo  bar
    A0 B0    0    1
       B1    2    3
    A1 B0    8    9
       B1   10   11

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4