pandas.DataFrame.unstack
pandas 3.1.1 · DataFrame · method
Move an index level into the columns.
Call syntax
DataFrame.unstack(level=-1, fill_value=None, sort=True)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
level |
Optional Positional or keyword Default -1 |
int, str, or list of these Choose an index level by name or integer position. |
fill_value |
Optional Positional or keyword Default None |
scalar Supply a value to use in place of a missing position. |
sort |
Optional Positional or keyword Default True |
bool Choose whether the resulting labels or groups are sorted where supported. |
Returns
Series or DataFrame