Check whether only the upper case is present in a column of a DataFrame

In this python pandas program, we will check whether only the upper case is 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 uppercase is present in a column of a DataFrame using df[‘Uppercase’] = list(map(lambda x: x.isupper(), df[‘Name’])).
  4. It will create a new column in the dataframe that will contain True if the value in the name row contains all the uppercase characters or else False.
  5. The lambda function will check whether the value in the name column contains all the uppercase characters or not
  6. list() will create a list of all results after applying the lambda function to each value.
  7. Print the output.
				
					import pandas as pd
d = {'Name':['Kate','Jason','ROBERT','MARK','Dwyane']}
df = pd.DataFrame(d)
df['Uppercase'] = list(map(lambda x: x.isupper(), df['Name']))
print(df)
				
			

Output :

				
					0     Name  Uppercase
0    Kate      False
1   Jason      False
2  ROBERT       True
3    MARK       True
4  Dwyane      False
				
			

convert all the string values in the DataFrame to uppercases

check whether only the lower case is present in a given column of a DataFrame

Leave a Comment