Python Practice › Pandas Programs › Program 74
Alphabetic-only check
Write a pandas program to check which values contain only letters.
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
str.isalpha(); spaces make it False.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.