Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY CYBERSECURITY DATA SCIENCE
     ❯   

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).set_index(["name", "age"])

newdf = df.droplevel(0)
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