pandas.Series.unstack

pandas 3.1.1 · Series and accessors · method

Move an index level into the columns.

Call syntax

Series.unstack(level=-1, fill_value=None, sort=True)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted 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 value

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

DataFrame