unstack(self, level: 'Level' = -1, fill_value=None)
Returns a DataFrame having a new level of column labels whose inner-most level consists of the pivoted index labels.
If the index is not a MultiIndex, the output will be a Series (the analogue of stack when the columns are not a MultiIndex).
Reference the user guide <reshaping.stacking>
for more examples.
Level(s) of index to unstack, can pass level name.
Replace NaN with this value if the unstack produces missing values.
Pivot a level of the (necessarily hierarchical) index labels.
DataFrame.pivot
Pivot a table based on column values.
DataFrame.stack
Pivot a level of the column labels (inverse operation from :None:None:`unstack`
).
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),This example is valid syntax, but we were not able to check execution
... ('two', 'a'), ('two', 'b')])
... s = pd.Series(np.arange(1.0, 5.0), index=index)
... s one a 1.0 b 2.0 two a 3.0 b 4.0 dtype: float64
>>> s.unstack(level=-1) a b one 1.0 2.0 two 3.0 4.0This example is valid syntax, but we were not able to check execution
>>> s.unstack(level=0) one two a 1.0 3.0 b 2.0 4.0This example is valid syntax, but we were not able to check execution
>>> df = s.unstack(level=0)See :
... df.unstack() one a 1.0 b 2.0 two a 3.0 b 4.0 dtype: float64
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.frame.DataFrame.explode
pandas.core.frame.DataFrame.pivot
pandas.core.reshape.pivot.pivot
pandas.core.frame.DataFrame.stack
pandas.core.reshape.melt.wide_to_long
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them