Skip to content

Commit 595cee8

Browse files
committed
DOC: Improving docstring of take method
1 parent ad24759 commit 595cee8

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

Diff for: pandas/core/generic.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,8 @@ def __delitem__(self, key):
19391939

19401940
def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
19411941
"""
1942-
Analogous to ndarray.take
1942+
Return an object formed from the elements in the given indices along an
1943+
axis
19431944
19441945
Parameters
19451946
----------
@@ -1948,6 +1949,44 @@ def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
19481949
convert : translate neg to pos indices (default)
19491950
is_copy : mark the returned frame as a copy
19501951
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+
19511990
Returns
19521991
-------
19531992
taken : type of caller

0 commit comments

Comments
 (0)