Skip to content

Commit d00cf3d

Browse files
datapythonista3553x
authored andcommitted
DOC: Improving docstring of pop method (pandas-dev#16416) (pandas-dev#16520)
1 parent 4839111 commit d00cf3d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pandas/core/generic.py

+37
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,43 @@ def swapaxes(self, axis1, axis2, copy=True):
547547
def pop(self, item):
548548
"""
549549
Return item and drop from frame. Raise KeyError if not found.
550+
551+
Parameters
552+
----------
553+
item : str
554+
Column label to be popped
555+
556+
Returns
557+
-------
558+
popped : Series
559+
560+
Examples
561+
--------
562+
>>> df = pd.DataFrame([('falcon', 'bird', 389.0),
563+
... ('parrot', 'bird', 24.0),
564+
... ('lion', 'mammal', 80.5),
565+
... ('monkey', 'mammal', np.nan)],
566+
... columns=('name', 'class', 'max_speed'))
567+
>>> df
568+
name class max_speed
569+
0 falcon bird 389.0
570+
1 parrot bird 24.0
571+
2 lion mammal 80.5
572+
3 monkey mammal NaN
573+
574+
>>> df.pop('class')
575+
0 bird
576+
1 bird
577+
2 mammal
578+
3 mammal
579+
Name: class, dtype: object
580+
581+
>>> df
582+
name max_speed
583+
0 falcon 389.0
584+
1 parrot 24.0
585+
2 lion 80.5
586+
3 monkey NaN
550587
"""
551588
result = self[item]
552589
del self[item]

0 commit comments

Comments
 (0)