Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Index.get_indexer_non_unique#

Index.get_indexer_non_unique(target)[source]#

Compute indexer and mask for new index given the current index.

The indexer should be then used as an input to ndarray.take to align thecurrent data to the new index.

Parameters:
targetIndex
Returns:
indexernp.ndarray[np.intp]

Integers from 0 to n - 1 indicating that the index at thesepositions matches the corresponding target values. Missing valuesin the target are marked by -1.

missingnp.ndarray[np.intp]

An indexer into the target of the values not found.These correspond to the -1 in the indexer array.

Examples

>>>index=pd.Index(['c','b','a','b','b'])>>>index.get_indexer_non_unique(['b','b'])(array([1, 3, 4, 1, 3, 4]), array([], dtype=int64))

In the example below there are no matched values.

>>>index=pd.Index(['c','b','a','b','b'])>>>index.get_indexer_non_unique(['q','r','t'])(array([-1, -1, -1]), array([0, 1, 2]))

For this reason, the returnedindexer contains only integers equal to -1.It demonstrates that there’s no match between the index and thetargetvalues at these positions. The mask [0, 1, 2] in the return value shows thatthe first, second, and third elements are missing.

Notice that the return value is a tuple contains two items. In the examplebelow the first item is an array of locations inindex. The seconditem is a mask shows that the first and third elements are missing.

>>>index=pd.Index(['c','b','a','b','b'])>>>index.get_indexer_non_unique(['f','b','s'])(array([-1,  1,  3,  4, -1]), array([0, 2]))

[8]ページ先頭

©2009-2025 Movatter.jp