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
- Import pandas library as pd.
- Create a dataframe using pd.DataFrame().
- Check whether only the uppercase is present in a column of a DataFrame using df[‘Uppercase’] = list(map(lambda x: x.isupper(), df[‘Name’])).
- 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.
- The lambda function will check whether the value in the name column contains all the uppercase characters or not
- list() will create a list of all results after applying the lambda function to each value.
- 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