pandas.DataFrame.xs
pandas 3.1.1 · DataFrame · method
Select a cross-section by a label, optionally within one level of a hierarchical index.
Call syntax
DataFrame.xs(key, axis=0, level=None, drop_level=True)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
key |
Required Positional or keyword |
label or tuple of label Provide the lookup key, or a transformation callable for a sorting method. |
axis |
Optional Positional or keyword Default 0 |
{0 or 'index', 1 or 'columns'} Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
level |
Optional Positional or keyword Default None |
object Choose an index level by name or integer position. |
drop_level |
Optional Positional or keyword Default True |
bool Choose whether selected hierarchical levels are removed from the resulting index. |
Returns
Series or DataFrame