pandas.DataFrame.drop

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.

param labels
single label or list-like

Index or column labels to drop.

param axis
{0 or ‘index’, 1 or ‘columns’}, default 0

Whether to drop labels from the index (0 or ‘index’) or columns (1 or ‘columns’).

param index
single label or list-like

Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).

New in version 0.21.0.

param columns
single label or list-like

Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).

New in version 0.21.0.

param level
int or level name, optional

For MultiIndex, level from which the labels will be removed.

param inplace
bool, default False

If True, do operation inplace and return None.

param errors
{‘ignore’, ‘raise’}, default ‘raise’

If ‘ignore’, suppress error and only existing labels are dropped.

return

DataFrame DataFrame without the removed index or column labels.

raises
KeyError

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

Limitations

  • Parameters labels, axis, index, level and inplace are currently unsupported.

  • Parameter columns is required and is expected to be a Literal value with one column name

    or Tuple with columns names.

  • Supported errors can be {raise, ignore}, default raise. If ignore, suppress error and only

    existing labels are dropped.

Examples

Drop specified columns from DataFrame.
import pandas as pd
from numba import njit


@njit
def dataframe_drop():
    df = pd.DataFrame({'A': [1.0, 2.0, 3.0, 1.0], 'B': [4, 5, 6, 7], 'C': ['a', 'b', 'c', 'd']})

    return df.drop(columns='A')


print(dataframe_drop())
$ python ./dataframe/dataframe_drop.py
   B  C
0  4  a
1  5  b
2  6  c
3  7  d

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.