bigframes.pandas.DataFrame.unstack#
- DataFrame.unstack(level: Hashable | Sequence[Hashable] = -1, *, fill_value: Any = None)[source]#
Pivot a level of the (necessarily hierarchical) index labels.
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).
Examples:
>>> df = bpd.DataFrame({'A': [1, 3], 'B': [2, 4]}, index=['foo', 'bar']) >>> df A B foo 1 2 bar 3 4 [2 rows x 2 columns]
>>> df.unstack() A foo 1 bar 3 B foo 2 bar 4 dtype: Int64
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'), ('two', 'a')]) >>> df = bpd.DataFrame({'val': [1, 2, 3]}, index=index) >>> df.unstack(fill_value=0) val level_1 a b level_0 one 1 2 two 3 0 [2 rows x 2 columns]
- Parameters:
- Returns:
DataFrame or Series.
- Return type: