Python Practice › Pandas Programs › Program 73
Numeric-only check
Write a pandas program to check which values contain only digits.
Input
["Pass", "88", "2nd class", "90", "Distinction"]
Output
Marks is_numeric 0 Pass False 1 88 True 2 2nd class False 3 90 True 4 Distinction False
Approach
str.isnumeric().
Solution
import pandas as pddf = pd.DataFrame({"Marks": ["Pass", "88", "2nd class", "90", "Distinction"]})df["is_numeric"] = df["Marks"].str.isnumeric()print(df)Output
Marks is_numeric 0 Pass False 1 88 True 2 2nd class False 3 90 True 4 Distinction False
Learn the concept
New to this topic? Read the lesson, then come back.