Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame.drop Raises KeyError definition #25474

Merged
merged 3 commits into from
Feb 28, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3797,7 +3797,12 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
axis : {0 or 'index', 1 or 'columns'}, default 0
Whether to drop labels from the index (0 or 'index') or
columns (1 or 'columns').
index, columns : single label or list-like
index : single label or list-like
Alternative to specifying axis (``labels, axis=0``
is equivalent to ``index=labels``).

.. versionadded:: 0.21.0
columns : single label or list-like
Alternative to specifying axis (``labels, axis=1``
is equivalent to ``columns=labels``).

Expand All @@ -3813,11 +3818,12 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
Returns
-------
DataFrame
DataFrame without the removed index or column labels.

Raises
------
KeyError
If none of the labels are found in the selected axis
If one of the labels is not found in the selected axis.
MaxVanDeursen marked this conversation as resolved.
Show resolved Hide resolved

See Also
--------
Expand All @@ -3830,7 +3836,7 @@ def drop(self, labels=None, axis=0, index=None, columns=None,

Examples
--------
>>> df = pd.DataFrame(np.arange(12).reshape(3,4),
>>> df = pd.DataFrame(np.arange(12).reshape(3, 4),
... columns=['A', 'B', 'C', 'D'])
>>> df
A B C D
Expand Down Expand Up @@ -3867,7 +3873,7 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
>>> df = pd.DataFrame(index=midx, columns=['big', 'small'],
... data=[[45, 30], [200, 100], [1.5, 1], [30, 20],
... [250, 150], [1.5, 0.8], [320, 250],
... [1, 0.8], [0.3,0.2]])
... [1, 0.8], [0.3, 0.2]])
>>> df
big small
lama speed 45.0 30.0
Expand Down