@@ -1939,7 +1939,8 @@ def __delitem__(self, key):
1939
1939
1940
1940
def take (self , indices , axis = 0 , convert = True , is_copy = True , ** kwargs ):
1941
1941
"""
1942
- Analogous to ndarray.take
1942
+ Return an object formed from the elements in the given indices along an
1943
+ axis
1943
1944
1944
1945
Parameters
1945
1946
----------
@@ -1948,6 +1949,44 @@ def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
1948
1949
convert : translate neg to pos indices (default)
1949
1950
is_copy : mark the returned frame as a copy
1950
1951
1952
+ Examples
1953
+ --------
1954
+ >>> import numpy as np
1955
+ >>> import pandas as pd
1956
+ >>> df = pd.DataFrame([('falcon', 'bird', 389.0),
1957
+ ('parrot', 'bird', 24.0),
1958
+ ('lion', 'mammal', 80.5),
1959
+ ('monkey', 'mammal', np.nan)],
1960
+ columns=('name', 'class', 'max_speed'))
1961
+ >>> df
1962
+ name class max_speed
1963
+ 0 falcon bird 389.0
1964
+ 1 parrot bird 24.0
1965
+ 2 lion mammal 80.5
1966
+ 3 monkey mammal NaN
1967
+
1968
+ Take elements at indices 0 and 3 along the axis 0 (default)
1969
+
1970
+ >>> df.take([0, 3])
1971
+ 0 falcon bird 389.0
1972
+ 3 monkey mammal NaN
1973
+
1974
+ Take elements at indices 1 and 2 along the axis 1
1975
+
1976
+ >>> df.take([1, 2], axis=1)
1977
+ class max_speed
1978
+ 0 bird 389.0
1979
+ 1 bird 24.0
1980
+ 2 mammal 80.5
1981
+ 3 mammal NaN
1982
+
1983
+ Also, we may take elements using negative integers for pos indices
1984
+
1985
+ >>> df.take([-1, -2])
1986
+ name class max_speed
1987
+ 3 monkey mammal NaN
1988
+ 2 lion mammal 80.5
1989
+
1951
1990
Returns
1952
1991
-------
1953
1992
taken : type of caller
0 commit comments