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 asPivotWiderOptions.key_names.All output struct fields have the same type aspivot_values.Each pivot key decides in which output field the corresponding pivot valueis 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. Thekey_nameswill be cast to the pivot key column type for matching.Behavior of unexpected pivot keys is controlled byunexpected_key_behaviorin PivotWiderOptions.

Parameters:
pivot_keysArray-like

Argument to compute function.

pivot_valuesArray-like

Argument to compute function.

key_namessequence ofstr

The pivot key names expected in the pivot key column.For each entry inkey_names, a column with the same name is emittedin the struct output.

unexpected_key_behaviorstr, default “ignore”

The behavior when pivot keys not inkey_names are encountered.Accepted values are “ignore”, “raise”.If “ignore”, unexpected keys are silently ignored.If “raise”, unexpected keys raise a KeyError.

optionspyarrow.compute.PivotWiderOptions, optional

Alternative way of passing options.

memory_poolpyarrow.MemoryPool, optional

If not passed, will allocate memory from the default memory pool.