bigframes.pandas.DataFrame.unstack#

DataFrame.unstack(level: Hashable | Sequence[Hashable] = -1)[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
Parameters:

level (int, str, or list of these, default -1 (last level)) – Level(s) of index to unstack, can pass level name.

Returns:

DataFrame or Series.

Return type:

bigframes.pandas.DataFrame or bigframes.pandas.Series