Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Python has some inbuilt methods to convert a string into lower, upper or Camel case. But these methods don’t work on list and other multi string objects. Pandas is a library for Data analysis which provides separate methods to convert all values in a series to respective text cases. Since, lower, upper and title are Python keywords too, .str has to be prefixed before calling these function on a Pandas series.
Series.str.lower() Series.str.upper() Series.str.title()
Parameters: Doesn’t take any parameter
Return Type: Series with new values
To download the CSV file used, Click Here.
In the following examples, the data frame used contains data of some employees. The image of data frame before any operations is attached below.
Example #1: Using
.lower() on a Series
In this example, .lower() function is being called by the First Name column and hence, all the values in the First name column will be converted in to lower case.
As shown in the output image of data frame, all values in the First name column have been converted into lower case.
Example #2: Using
.upper() on a Series
In this example, .upper() function is being called by the Team column and hence all the values in the Team column will be converted into upper case.
As shown in the output image of data frame, all values in the Team column have been converted into upper case.
Example #3: Using
.title() on a Series
In this example, .title() function is being called by the Team column and hence, all the values in the into column will be converted in to Camel case. Since the values in the Team column were already in camel case, it has been converted to Upper case before and then again to camel case in order to verify the functionality of .title() method.
As shown in the output image of data frame, all values in the Team column have been converted into Camel case.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course