title() function in pandas – Convert column to title case or proper case python

In this tutorial we will be using title() function in pandas to  convert the character column of the python dataframe to title case or proper case.

  • If the input string in any case (upper, lower or title), title() function in pandas converts the string to title case or proper case.

Lets look it with an Example

Create dataframe:

## create dataframe

import pandas as pd
d = {'Quarters' : ['quarter1','quarter2','quarter3','quarter4'],
     'Description' : ['First Quarter of the year', 'second quarter of the year', 'Third  Quarter of the year', 'FOURTH QUARTER OF THE YEAR']}
df=pd.DataFrame(d)
print df	

resultant dataframe will be

Convert the character column of the python Dataframe to title case or proper case pandas 1

 

# title function in python to convert the character column to title case or proper case

df['title_desc'] = map(lambda x: x.title(), df['Description'])
print df

title() function in pandas converts any case to the title case and stores it in the title_desc column of the dataframe, so the output will be

Convert the character column of the python Dataframe to title case or proper case pandas

 

previous title() function in pandas Convert the character column of the python Dataframe to title case or proper case pandas                                                                                                           next title() function in pandas Convert the character column of the python Dataframe to title case or proper case pandas

Author