Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame droplevel() Method

❮ DataFrame Reference


Example

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.


Syntax

dataframe.droplevel(level, axis)

Parameters

The axis parameter is a keyword argument.

Parameter Value Description
level   Required, a Number, String, or List specifying the level to drop
axis 0
1
'index'
'columns
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