Skip to main content
`Ctrl`+`K`

# pandas.Index.get_indexer_non_unique

Index.get_indexer_non_unique(target)

  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 the current data to the new index.

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

      Integers from 0 to n - 1 indicating that the index at these positions matches the corresponding target values. Missing values in 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 returned `indexer` contains only integers equal to -1. It demonstrates that there’s no match between the index and the `target` values at these positions. The mask [0, 1, 2] in the return value shows that the first, second, and third elements are missing.

  Notice that the return value is a tuple contains two items. In the example below the first item is an array of locations in `index`. The second item 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]))