Check for title case or proper case using istitle() Function in Pandas python

In this Section we will learn how to check for only title case or proper case in a column of dataframe using istitle() function in pandas python

Let’s see with an example

Create a dataframe

## create dataframe

import pandas as pd
d = {'Quarters' : ['QUARTER1','Quarter2','quarter3','quarter4'],
     'Revenue':[23400344.567,54363744.678,56789117.456,4132454.987]}
df=pd.DataFrame(d)
print df

The resultant dataframe will be

title case or proper case in a column of dataframe in python 1

 

Check for title case or proper case character in column of dataframe in python


# whether only proper case or title case is present in Quarters column of dataframe in Python

df['Quarters_istitle_case'] = map(lambda x: x.istitle(), df['Quarters'])
print df

 

istitle() Function in pandas python checks whether the string consists of only title case or proper case characters.

It returns True when only title case characters are present and it returns False when it does not have only title case.

The result is stored in the Quarters_istitle_case column of the dataframe.

So the resultant dataframe will be

title case or proper case in a column of dataframe in python 2

 

 

previous proper case in a column of dataframe python istitle() function in pandas                                                                                                           next proper case in a column of dataframe in python istitle() function in pandas

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.