Python Practice › Pandas Programs › Program 74

Alphabetic-only check

EasyPandas Programs · 74 of 95

Write a pandas program to check which values contain only letters.

Advertisement
Input
["Pass", "88", "First class", "90", "Distinction"]
Output
         Marks  is_alpha
0         Pass      True
1           88     False
2  First class     False
3           90     False
4  Distinction      True

Approach

  1. str.isalpha(); spaces make it False.

Solution

Python
import pandas as pddf = pd.DataFrame({"Marks": ["Pass", "88", "First class", "90", "Distinction"]})df["is_alpha"] = df["Marks"].str.isalpha()print(df)
Output
         Marks  is_alpha
0         Pass      True
1           88     False
2  First class     False
3           90     False
4  Distinction      True
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs