Python Practice › Pandas Programs › Program 45

Delete rows

EasyPandas Programs · 45 of 95

Write a pandas program to delete John’s record.

Advertisement
Output
    name  age
0   Alex   30
2  Peter   29
3  Klaus   33

Approach

  1. Keep the rows that do not match.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, 27, 29, 33]})print(df[df["name"] != "John"])
Output
    name  age
0   Alex   30
2  Peter   29
3  Klaus   33
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs