Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.drop

DataFrame.drop removes selected labels from rows or columns. Use index= or columns= for readable, axis-free calls; it returns a new DataFrame unless inplace=True.

How it works

DataFrame.drop removes selected row-index or column labels. Pass labels with an axis, or use index and columns directly; by default it returns a new DataFrame, while inplace=True changes the object and returns None.

Syntax

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

Parameters

NameTypeDescription
labelssingle label or list-likeIndex or column labels to drop.
axis{0 or 'index', 1 or 'columns'}, default 0Select rows with 0 or 'index', or columns with 1 or 'columns'.
indexsingle label or iterable of labelsAlternative to labels with axis=0.
columnssingle label or iterable of labelsAlternative to labels with axis=1.
levelint or level name, optionalMultiIndex level from which labels are removed.
inplacebool, default FalseModify the DataFrame in place.
errors{‘ignore’, ‘raise’}, default ‘raise’Whether to raise for missing labels; 'ignore' suppresses those errors.

Returns

DataFrame or None: the DataFrame with specified index or column labels removed, or None when inplace=True.

Key points

  • Use DataFrame.drop to remove selected row-index or column labels.
  • Provide labels plus axis=0 or 'index' for rows, or axis=1 or 'columns' for columns.
  • The index= and columns= keywords provide clearer alternatives to axis-based calls.
  • Set level to an integer position or level name when dropping labels from a MultiIndex.
  • With the default inplace=False, the method returns a DataFrame containing the remaining labels.
  • An in-place drop returns None rather than the modified DataFrame.

Common mistakes

  • A tuple is interpreted as one label, so pass a list when you intend to remove multiple tuple-like labels.
  • The default errors='raise' fails when a requested label is absent; use errors='ignore' when missing labels should be skipped.

Example: Drop columns and rows

import pandas as pd

orders = pd.DataFrame({
    "customer": ["A", "B", "C"],
    "total": [12, 25, 18],
}, index=[101, 102, 103])

without_total = orders.drop(columns="total")
without_b = orders.drop(index=102)

print(without_total)
print(without_b)

Use the explicit columns or index keyword to remove labels without relying on axis numbers.

When to use it

Select columns

Remove unwanted fields while preserving the source DataFrame.

Filter rows by label

Exclude records identified by their index labels.

Edit a MultiIndex

Remove labels from one level of a hierarchical index.

Tolerate missing labels

Process partially varying schemas without failing on absent labels.

Interview questions

QWhat does DataFrame.drop do, and how does axis affect it?

It removes specified labels from rows or columns. The axis argument selects index labels with 0 or 'index', and column labels with 1 or 'columns'.

Follow-up: How can the same operation be expressed without axis? Use index= for rows or columns= for columns; these are alternatives to labels combined with the corresponding axis.

QWhat does inplace change?

The default is inplace=False, so the method returns a DataFrame with the requested labels removed and leaves the original unchanged. With inplace=True, it modifies the object and returns None.

Follow-up: When is inplace=True observable from the return value? The result is None, so callers must not assign it as though it were the modified DataFrame.

QHow does drop work with a MultiIndex?

For a MultiIndex, level identifies the index level from which labels are removed. It can be an integer level position or a level name.

Follow-up: Why specify level? It disambiguates removal in a multi-level index and avoids treating the label as a match across every level.

  • DataFrame.pop
  • DataFrame.drop_duplicates
  • DataFrame.dropna
  • DataFrame.rename
  • DataFrame.set_axis

Source: pandas.DataFrame.drop. Checked 2026-10-15.