pandas 1.4.2

ParametersReturns
_factorize_keys(lk: 'ArrayLike', rk: 'ArrayLike', sort: 'bool' = True, how: 'str' = 'inner') -> 'tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]'

This is used to get the join indexers to be used when merging DataFrames.

Parameters

lk : array-like

Left key.

rk : array-like

Right key.

sort : bool, defaults to True

If True, the encoding is done such that the unique elements in the keys are sorted.

how : {‘left’, ‘right’, ‘outer’, ‘inner’}, default ‘inner’

Type of merge.

Returns

np.ndarray[np.intp]

Left (resp. right if called with :None:None:`key='right'`) labels, as enumerated type.

np.ndarray[np.intp]

Right (resp. left if called with :None:None:`key='right'`) labels, as enumerated type.

int

Number of unique elements in union of left and right labels.

Encode left and right keys as enumerated types.

See Also

algorithms.factorize

Encode the object as an enumerated type or categorical variable.

merge

Merge DataFrame or named Series objects with a database-style join.

Examples

This example is valid syntax, but we were not able to check execution
>>> lk = np.array(["a", "c", "b"])
... rk = np.array(["a", "c"])

Here, the unique values are :None:None:`'a', 'b', 'c'`. With the default :None:None:`sort=True`, the encoding will be :None:None:`{0: 'a', 1: 'b', 2: 'c'}`:

This example is valid syntax, but we were not able to check execution
>>> pd.core.reshape.merge._factorize_keys(lk, rk)
(array([0, 2, 1]), array([0, 2]), 3)

With the :None:None:`sort=False`, the encoding will correspond to the order in which the unique elements first appear: :None:None:`{0: 'a', 1: 'c', 2: 'b'}`:

This example is valid syntax, but we were not able to check execution
>>> pd.core.reshape.merge._factorize_keys(lk, rk, sort=False)
(array([0, 1, 2]), array([0, 1]), 3)
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/reshape/merge.py#2072
type: <class 'function'>
Commit: