pandas.Series.take¶
Return the elements in the given positional indices along an axis.
This means that we are not indexing according to actual values in the index attribute of the object. We are indexing according to the actual position of the element in the object.
- param indices
- array-like
An array of ints indicating which positions to take.
- param axis
- {0 or ‘index’, 1 or ‘columns’, None}, default 0
The axis on which to select elements.
0
means that we are selecting rows,1
means that we are selecting columns.
- param is_copy
- bool, default True
Whether to return a copy of the original object or not. **kwargs For compatibility with
numpy.take()
. Has no effect on the output.
- return
taken : same type as caller An array-like containing the elements taken from the object.
Limitations¶
Parameter axis
is supported only with default values 0
and 'index'
.
Parameter is_copy
is supported only with default value False
.
Examples¶
import pandas as pd
from numba import njit
@njit
def series_take():
series = pd.Series([5, 4, 3, 2, 1])
return series.take([4, 1]) # Expect series of 4, 1
print(series_take())
$ python ./series/series_take.py
4 1
1 4
dtype: int64
See also
- DataFrame.loc
Select a subset of a DataFrame by labels.
- DataFrame.iloc
Select a subset of a DataFrame by positions.