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)
- Python String Title method
- Python | String upper()
- isupper(), islower(), lower(), upper() in Python and their applications
- Python program to count upper and lower case characters without using inbuilt functions
- Python regex to find sequences of one upper case letter followed by lower case letters
- numpy string operations | title() function
- Python | pandas.map()
- Python | Pandas Series.dt.tz
- Python | Pandas TimedeltaIndex.contains
- Python | Pandas dataframe.cov()
- Python | Pandas DataFrame.ix[ ]
- Python | Pandas Series.dt.second
- Python | Pandas Series.max()
- Python | Pandas Timestamp.now
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.