Remove rows or columns by specifying label names and corresponding axis, or by directly specifying index or column names. When using a multi-index, labels on different levels can be removed by specifying the level. See the user guide for more information about the now unused levels.
Parameters:
labels: single label or iterable of labels
Index or column labels to drop. A tuple will be used as a single label and not treated as an iterable.
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: single label or iterable of labels
Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).
columns: single label or iterable of labels
Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).
level: int or level name, optional
For MultiIndex, level from which the labels will be removed.
inplace: bool, default False
If False, return a copy. Otherwise, do operation in place and return None.
errors: {‘ignore’, ‘raise’}, default ‘raise’
If ‘ignore’, suppress error and only existing labels are dropped.
Returns:
DataFrame or None
Returns DataFrame or None DataFrame with the specified index or column labels removed or None if inplace=True.
Raises:
KeyError
If any of the labels is not found in the selected axis.
See also:
DataFrame.loc
Label-location based indexer for selection by label.
DataFrame.dropna
Return DataFrame with labels on given axis omitted where (all or any) data are missing.
DataFrame.drop_duplicates
Return DataFrame with duplicate rows removed, optionally only considering certain columns.
Series.drop
Return Series with specified index labels removed.
Examples:
>>> df = pd.DataFrame(np.arange(12).reshape(3, 4), columns=["A", "B", "C", "D"])>>> df A B C D0 0 1 2 31 4 5 6 72 8 9 10 11
Drop a specific index combination from the MultiIndex DataFrame, i.e., drop the combination 'falcon' and 'weight', which deletes only the corresponding row