pandas.DataFrame.pivot

pandas 3.1.1 · DataFrame · method

Move distinct values into columns. Each output row–column pair needs a single source value.

Call syntax

DataFrame.pivot(*, columns, index=…, values=…)

Run the example

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

Parameters

ParameterRequirementAccepted values and behavior
columns Required
Keyword only
Hashable or a sequence of the previous

Supply column labels or control how columns are handled.

index Optional
Keyword only
Hashable or a sequence of the previous

Supply row labels or control how existing row labels are used.

values Optional
Keyword only
Hashable or a sequence of the previous

Supply values to transform, match, aggregate, or use as data.

Returns

DataFrame