Pandas DataFrame droplevel() Method
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 |
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-