@@ -2063,57 +2063,73 @@ def __delitem__(self, key):
20632063
20642064 def take (self , indices , axis = 0 , convert = True , is_copy = True , ** kwargs ):
20652065 """
2066- Return an object formed from the elements in the given indices along an
2067- axis
2066+ Return the elements in the given *positional* indices along an axis.
2067+
2068+ This means that we are not indexing according to actual values in
2069+ the index attribute of the object. We are indexing according to the
2070+ actual position of the element in the object's array of values.
20682071
20692072 Parameters
20702073 ----------
2071- indices : list / array of ints
2074+ indices : array-like
2075+ An array of ints indicating which positions to take.
20722076 axis : int, default 0
2073- convert : translate neg to pos indices (default)
2074- is_copy : mark the returned frame as a copy
2077+ The axis on which to select elements. "0" means that we are
2078+ selecting rows, "1" means that we are selecting columns, etc.
2079+ convert : bool, default True
2080+ Whether to convert negative indices to positive ones.
2081+ is_copy : bool, default True
2082+ Whether to return a copy of the original object or not.
20752083
20762084 Examples
20772085 --------
2078- >>> import numpy as np
2079- >>> import pandas as pd
20802086 >>> df = pd.DataFrame([('falcon', 'bird', 389.0),
20812087 ('parrot', 'bird', 24.0),
20822088 ('lion', 'mammal', 80.5),
20832089 ('monkey', 'mammal', np.nan)],
2084- columns=('name', 'class', 'max_speed'))
2090+ columns=('name', 'class', 'max_speed'),
2091+ index=[0, 3, 2, 1])
20852092 >>> df
20862093 name class max_speed
20872094 0 falcon bird 389.0
2088- 1 parrot bird 24.0
2095+ 3 parrot bird 24.0
20892096 2 lion mammal 80.5
2090- 3 monkey mammal NaN
2097+ 1 monkey mammal NaN
20912098
2092- Take elements at indices 0 and 3 along the axis 0 (default)
2099+ Take elements at positions 0 and 3 along the axis 0 (default).
2100+
2101+ Note how the actual indices selected (0 and 1) do not correspond to
2102+ our selected indices 0 and 3. That's because we are selecting the 0th
2103+ and 3rd rows, not rows whose indices equal 0 and 3.
20932104
20942105 >>> df.take([0, 3])
20952106 0 falcon bird 389.0
2096- 3 monkey mammal NaN
2107+ 1 monkey mammal NaN
20972108
20982109 Take elements at indices 1 and 2 along the axis 1
20992110
21002111 >>> df.take([1, 2], axis=1)
21012112 class max_speed
21022113 0 bird 389.0
2103- 1 bird 24.0
2114+ 3 bird 24.0
21042115 2 mammal 80.5
2105- 3 mammal NaN
2116+ 1 mammal NaN
21062117
2107- Also, we may take elements using negative integers for pos indices
2118+ We may take elements using negative integers for positive indices.
21082119
21092120 >>> df.take([-1, -2])
21102121 name class max_speed
2111- 3 monkey mammal NaN
2122+ 1 monkey mammal NaN
21122123 2 lion mammal 80.5
21132124
21142125 Returns
21152126 -------
21162127 taken : type of caller
2128+ An array-like containing the elements taken from the object.
2129+
2130+ See Also
2131+ --------
2132+ ndarray.take
21172133 """
21182134 nv .validate_take (tuple (), kwargs )
21192135 self ._consolidate_inplace ()
0 commit comments