Check whether only alphabetic values present in a column of a DataFrame

In this python pandas program, we will only alphabetic values present in a column of a DataFrame using the pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Check whether only the alphabets are present in a record of a column of a DataFrame using df[‘Characters’] = list(map(lambda x: x.isalpha(), df[‘Name’])).
  4. It will create a new column in the dataframe that will contain True if the value in the row contains only the alphabet or else False.
  5. The lambda function will check whether the value in the column contains only the alphabet or not.
  6. map() works as an iterator to return a result after applying a function to every item of an iterable 
  7. list() will create a list of all results after applying the lambda function to each value.
  8. Print the output.
				
					import pandas as pd
d = {'Marks':['Pass','88','First Class','90','Distinction']}
df = pd.DataFrame(d)
df['Characters'] = list(map(lambda x: x.isalpha(), df['Marks']))
print(df)
				
			

Output :

				
					0        Marks  Characters
0         Pass        True
1           88       False
2  First Class       False
3           90       False
4  Distinction        True

				
			

check whether only numeric values are present in a column of a DataFrame

get the length of the integer of a column in a DataFrame

Leave a Comment