w3resource

Pandas DataFrame: drop() function

DataFrame - drop() function

The drop() function is used to drop specified labels from rows or columns.

Remove rows or columns by specifying label names and corresponding axis, or by specifying directly index or column names. When using a multi-index, labels on different levels can be removed by specifying the level.

Syntax:

DataFrame.drop(self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')

Parameters:

Name Description Type/Default Value Required / Optional
labels               

Index or column labels to drop.

single label or list-like Required
axis    Whether to drop labels from the index (0 or ‘index’) or columns (1 or ‘columns’). {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required
index   Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).  single label or list-like Required
columns   Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).  single label or list-like Required
level   For MultiIndex, level from which the labels will be removed.  int or level name Optional
inplace  If True, do operation inplace and return None. bool
Default Value: False
Required
errors   If ‘ignore’, suppress error and only existing labels are dropped. {‘ignore’, ‘raise’}
Default Value: ‘raise’
Required

Returns: DataFrame
DataFrame without the removed index or column labels.

Raises: KeyError
If any of the labels is not found in the selected axis.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - between_time() function
Next: DataFrame - equals() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/dataframe/dataframe-drop.php