pandas.DataFrame.swaplevel
pandas 3.1.1 · DataFrame · method
Exchange two levels of a hierarchical index.
Call syntax
DataFrame.swaplevel(i=-2, j=-1, axis=0)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
i |
Optional Positional or keyword Default -2 |
int or str |
j |
Optional Positional or keyword Default -1 |
int or str |
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. |
Returns
DataFrame