Skip to main content
`Ctrl`+`K`

# pandas.api.extensions.ExtensionArray.insert

ExtensionArray.insert(loc, item)

  Insert an item at the given position.

  This method creates a new ExtensionArray with the specified item inserted at the given index. The original array is not modified.

  Parameters:
    loc int

      Index where the item needs to be inserted.

    item scalar-like

      Value to be inserted.

  Returns:
    ExtensionArray

      With item inserted at loc.

  See also

  `Index.insert`

    Make new Index inserting new item at location.

  Notes

  This method should be both type and dtype-preserving. If the item cannot be held in an array of this type/dtype, either ValueError or TypeError should be raised.

  The default implementation relies on _from_sequence to raise on invalid items.

  Examples

      >>> arr = pd.array([1, 2, 3])
      >>> arr.insert(2, -1)
      <IntegerArray>
      [1, 2, -1, 3]
      Length: 4, dtype: Int64