Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame droplevel() Method

❮ DataFrame Reference


Drop the second row (index 1) of the DataFrame:

import pandas as pd

data = {
  "name": ["Bill", "Bob", "Betty"],
  "age": [50, 50, 30],
  "qualified": [True, False, False]
df = pd.DataFrame(data)

newdf = df.drop(1)
Try it Yourself »

Definition and Usage

The droplevel() method removes the specified rows or columns.

You can specify the row or column by using the index or label.


dataframe.droplevel(level, axis)


The axis parameter is a keyword argument.

Parameter Value Description
level   Required, a Number, String, or List specifying the level to drop
axis 0
Optional, default 0. Specifies the axis to remove from

Return Value

A DataFrame with the specified rows/columns removed.

This method does not change the original DataFrame-

❮ DataFrame Reference