Skip to content

Commit 8b733c2

Browse files
matagusgfyoung
authored andcommitted
DOC: Improving docstring of take method
1 parent 58d8729 commit 8b733c2

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
@@ -2063,7 +2063,8 @@ def __delitem__(self, key):
20632063

20642064
def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
20652065
"""
2066-
Analogous to ndarray.take
2066+
Return an object formed from the elements in the given indices along an
2067+
axis
20672068
20682069
Parameters
20692070
----------
@@ -2072,6 +2073,44 @@ def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
20722073
convert : translate neg to pos indices (default)
20732074
is_copy : mark the returned frame as a copy
20742075
2076+
Examples
2077+
--------
2078+
>>> import numpy as np
2079+
>>> import pandas as pd
2080+
>>> df = pd.DataFrame([('falcon', 'bird', 389.0),
2081+
('parrot', 'bird', 24.0),
2082+
('lion', 'mammal', 80.5),
2083+
('monkey', 'mammal', np.nan)],
2084+
columns=('name', 'class', 'max_speed'))
2085+
>>> df
2086+
name class max_speed
2087+
0 falcon bird 389.0
2088+
1 parrot bird 24.0
2089+
2 lion mammal 80.5
2090+
3 monkey mammal NaN
2091+
2092+
Take elements at indices 0 and 3 along the axis 0 (default)
2093+
2094+
>>> df.take([0, 3])
2095+
0 falcon bird 389.0
2096+
3 monkey mammal NaN
2097+
2098+
Take elements at indices 1 and 2 along the axis 1
2099+
2100+
>>> df.take([1, 2], axis=1)
2101+
class max_speed
2102+
0 bird 389.0
2103+
1 bird 24.0
2104+
2 mammal 80.5
2105+
3 mammal NaN
2106+
2107+
Also, we may take elements using negative integers for pos indices
2108+
2109+
>>> df.take([-1, -2])
2110+
name class max_speed
2111+
3 monkey mammal NaN
2112+
2 lion mammal 80.5
2113+
20752114
Returns
20762115
-------
20772116
taken : type of caller

0 commit comments

Comments
 (0)