Python Practice › Pandas Programs › Program 78

Keep only words

EasyPandas Programs · 78 of 95

Write a pandas program to remove the numbers from an address column and keep the words.

Advertisement
Output
     Name             Address           words
0  Ramesh  297 shukrawar peth  shukrawar peth
1  Suresh    200 ravivar peth    ravivar peth
2  Sanket   090 shanivar peth   shanivar peth

Approach

  1. str.replace(r"\d+", "") then strip.

Solution

Python
import pandas as pddf = pd.DataFrame({"Name": ["Ramesh", "Suresh", "Sanket"],                   "Address": ["297 shukrawar peth", "200 ravivar peth", "090 shanivar peth"]})df["words"] = df["Address"].str.replace(r"\d+", "", regex=True).str.strip()print(df)
Output
     Name             Address           words
0  Ramesh  297 shukrawar peth  shukrawar peth
1  Suresh    200 ravivar peth    ravivar peth
2  Sanket   090 shanivar peth   shanivar peth
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs