Changing the Case of String Columns in a Pandas DataFrame

Python
Data Preprocessing

In this example we convert the Name column within the df dataframe to upper case, lower case, title case (where the first letter of each word is uppercase) and finally we capitalise the string (make only the first letter of the entire string uppercase).

 1|  # uppercase
 2|  df['Name'] =  df['Name'].str.upper()
 3|  
 4|  # lowercase
 5|  df['Name'] =  df['Name'].str.lower()
 6|  
 7|  # titlecase (where the first letter of each word is uppercase)
 8|  df['Name'] =  df['Name'].str.title()
 9|  
10|  # capitalize (make only the first letter of the entire string uppercase)
11|  df['Name'] =  df['Name'].str.capitalize()
1 Upvote
Tags: Cleaning | Strings
Did you find this snippet useful?

Sign up to bookmark this in your snippet library

Normalize Windowed Time Series
Python
Data Preprocessing

Scaler | Normalize | Scale | Min-max

4
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3