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.


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


Name Description Type/Default Value Required / Optional

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
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
errors   If ‘ignore’, suppress error and only existing labels are dropped. {‘ignore’, ‘raise’}
Default Value: ‘raise’

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

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


Download the Pandas DataFrame Notebooks from here.

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

Follow us on Facebook and Twitter for latest update.