pyarrow.compute.pivot_wider#
- pyarrow.compute.pivot_wider(pivot_keys, pivot_values, /, key_names, *, unexpected_key_behavior='ignore', options=None, memory_pool=None)#
Pivot values according to a pivot key column.
Output is a struct with as many fields as PivotWiderOptions.key_names. All output struct fields have the same type as pivot_values. Each pivot key decides in which output field the corresponding pivot value is emitted. If a pivot key doesn’t appear, null is emitted. If more than one non-null value is encountered for a given pivot key, Invalid is raised. The pivot key column can be string, binary or integer. The key_names will be cast to the pivot key column type for matching. Behavior of unexpected pivot keys is controlled by unexpected_key_behavior in PivotWiderOptions.
- Parameters:
- pivot_keysArray-like
Argument to compute function.
- pivot_valuesArray-like
Argument to compute function.
- key_namessequence of
str
The pivot key names expected in the pivot key column. For each entry in key_names, a column with the same name is emitted in the struct output.
- unexpected_key_behavior
str
, default “ignore” The behavior when pivot keys not in key_names are encountered. Accepted values are “ignore”, “raise”. If “ignore”, unexpected keys are silently ignored. If “raise”, unexpected keys raise a KeyError.
- options
pyarrow.compute.PivotWiderOptions
, optional Alternative way of passing options.
- memory_pool
pyarrow.MemoryPool
, optional If not passed, will allocate memory from the default memory pool.