MCPcopy
hub / github.com/pandas-dev/pandas / take

Method take

pandas/core/generic.py:3999–4096  ·  view source on GitHub ↗

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. Paramete

(self, indices, axis: Axis = 0, **kwargs)

Source from the content-addressed store, hash-verified

3997
3998 @final
3999 def take(self, indices, axis: Axis = 0, **kwargs) -> Self:
4000 """
4001 Return the elements in the given *positional* indices along an axis.
4002
4003 This means that we are not indexing according to actual values in
4004 the index attribute of the object. We are indexing according to the
4005 actual position of the element in the object.
4006
4007 Parameters
4008 ----------
4009 indices : array-like
4010 An array of ints indicating which positions to take.
4011 axis : {0 or 'index', 1 or 'columns'}, default 0
4012 The axis on which to select elements. ``0`` means that we are
4013 selecting rows, ``1`` means that we are selecting columns.
4014 For `Series` this parameter is unused and defaults to 0.
4015 **kwargs
4016 For compatibility with :meth:`numpy.take`. Has no effect on the
4017 output.
4018
4019 Returns
4020 -------
4021 same type as caller
4022 An array-like containing the elements taken from the object.
4023
4024 See Also
4025 --------
4026 DataFrame.loc : Select a subset of a DataFrame by labels.
4027 DataFrame.iloc : Select a subset of a DataFrame by positions.
4028 numpy.take : Take elements from an array along an axis.
4029
4030 Examples
4031 --------
4032 >>> df = pd.DataFrame(
4033 ... [
4034 ... ("falcon", "bird", 389.0),
4035 ... ("parrot", "bird", 24.0),
4036 ... ("lion", "mammal", 80.5),
4037 ... ("monkey", "mammal", np.nan),
4038 ... ],
4039 ... columns=["name", "class", "max_speed"],
4040 ... index=[0, 2, 3, 1],
4041 ... )
4042 >>> df
4043 name class max_speed
4044 0 falcon bird 389.0
4045 2 parrot bird 24.0
4046 3 lion mammal 80.5
4047 1 monkey mammal NaN
4048
4049 Take elements at positions 0 and 3 along the axis 0 (default).
4050
4051 Note how the actual indices selected (0 and 1) do not correspond to
4052 our selected indices 0 and 3. That's because we are selecting the 0th
4053 and 3rd rows, not rows whose indices equal 0 and 3.
4054
4055 >>> df.take([0, 3])
4056 name class max_speed

Callers 15

xsMethod · 0.95
_getitem_sliceMethod · 0.95
sampleMethod · 0.95
asofMethod · 0.95
at_timeMethod · 0.95
between_timeMethod · 0.95
time_takeMethod · 0.45
setupMethod · 0.45
setupMethod · 0.45
setupMethod · 0.45
setup_cacheMethod · 0.45
setupMethod · 0.45

Calls 4

copyMethod · 0.95
__finalize__Method · 0.80
_constructor_from_mgrMethod · 0.45

Tested by

no test coverage detected