Python | Pandas Series.str.lower(), upper() and title()

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.
Syntax:

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas package
import pandas as pd
  
# making data frame from csv file
data = pd.read_csv("employees.csv")
  
# converting and overwriting values in column
data["First Name"]= data["First Name"].str.lower()
  
# display
data

chevron_right


Output:
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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas package
import pandas as pd
  
# making data frame from csv file
data = pd.read_csv("employees.csv")
  
# converting and overwriting values in column
data["Team"]= data["Team"].str.upper()
  
# display
data

chevron_right


Output:
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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas package
import pandas as pd
  
# making data frame from csv file
data = pd.read_csv("employees.csv")
  
# converting and overwriting values in column
data["Team"]= data["Team"].str.upper().str.title()
  
# display
data

chevron_right


Output:
As shown in the output image of data frame, all values in the Team column have been converted into Camel case.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.