pandas 1.4.2

NotesParametersRaisesReturnsBackRef
take(arr, indices: 'TakeIndexer', axis: 'int' = 0, allow_fill: 'bool' = False, fill_value=None)

Notes

When allow_fill is False, :None:None:`indices` may be whatever dimensionality is accepted by NumPy for :None:None:`arr`.

When allow_fill is True, :None:None:`indices` should be 1-D.

Parameters

arr : array-like or scalar value

Non array-likes (sequences/scalars without a dtype) are coerced to an ndarray.

indices : sequence of int or one-dimensional np.ndarray of int

Indices to be taken.

axis : int, default 0

The axis over which to select values.

allow_fill : bool, default False

How to handle negative values in :None:None:`indices`.

  • False: negative values in :None:None:`indices` indicate positional indices from the right (the default). This is similar to numpy.take .

  • True: negative values in :None:None:`indices` indicate missing values. These values are set to :None:None:`fill_value`. Any other negative values raise a ValueError .

fill_value : any, optional

Fill value to use for NA-indices when allow_fill is True. This may be None , in which case the default NA value for the type ( self.dtype.na_value ) is used.

For multi-dimensional :None:None:`arr`, each element is filled with :None:None:`fill_value`.

Raises

IndexError

When :None:None:`indices` is out of bounds for the array.

ValueError

When the indexer contains negative values other than -1 and allow_fill is True.

Returns

ndarray or ExtensionArray

Same type as the input.

Take elements from an array.

See Also

numpy.take

Take elements from an array along an axis.

Examples

This example is valid syntax, but we were not able to check execution
>>> from pandas.api.extensions import take

With the default allow_fill=False , negative numbers indicate positional indices from the right.

This example is valid syntax, but we were not able to check execution
>>> take(np.array([10, 20, 30]), [0, 0, -1])
array([10, 10, 30])

Setting allow_fill=True will place :None:None:`fill_value` in those positions.

This example is valid syntax, but we were not able to check execution
>>> take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True)
array([10., 10., nan])
This example is valid syntax, but we were not able to check execution
>>> take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True,
...  fill_value=-10) array([ 10, 10, -10])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.algorithms.take

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/algorithms.py#1352
type: <class 'function'>
Commit: