Python Practice › Pandas Programs › Program 76

Extract emails

EasyPandas Programs · 76 of 95

Write a pandas program to extract email addresses from a column.

Advertisement
Output
              Company_mail             email
0        TCS tcs@yahoo.com     tcs@yahoo.com
1   Apple apple@icloud.com  apple@icloud.com
2  Google google@gmail.com  google@gmail.com

Approach

  1. str.extract with a regex group.

Solution

Python
import pandas as pddf = pd.DataFrame({"Company_mail": ["TCS tcs@yahoo.com", "Apple apple@icloud.com", "Google google@gmail.com"]})df["email"] = df["Company_mail"].str.extract(r"([\w.+-]+@[\w-]+\.[\w.]+)", expand=False)print(df)
Output
              Company_mail             email
0        TCS tcs@yahoo.com     tcs@yahoo.com
1   Apple apple@icloud.com  apple@icloud.com
2  Google google@gmail.com  google@gmail.com

Learn the concept

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

More pandas programs

← All 95 Pandas Programs

Leave a Comment