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.
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Pandas - Convert the first and last character of each word to upper case in a series
- isupper(), islower(), lower(), upper() in Python and their applications
- Python program to count upper and lower case characters without using inbuilt functions
- Python | String upper()
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python - Extract Upper Case Characters
- Python - Obtain title, views and likes of YouTube video using BeautifulSoup
- numpy string operations | upper() function
- PyQt5 QDial - Setting Upper Bound
- PyQt5 QDial - Getting Upper Bound
- Python String Title method
- How to get title of a webpage using Selenium in Python?
- Python IMDbPY – Getting title from searched movie
- Matplotlib.pyplot.title() in Python
- Convert string to title case in Python
- title driver method - Selenium Python
- turtle.title() function in Python
- Python VLC MediaPlayer - Getting Full Title Description
- Python VLC MediaPlayer - Getting Title Description