Change text
Clean and standardize text by changing letter case, trimming spaces, or simplifying format.
Example Data
Follow along with right out of the box example data. Copy following data in the information request of the agent you are working in.
Before grouping, counting, or exporting text data, it's helpful to clean and standardize it. One row might say “sweden”, another “Sweden”, and another “SWEDEN” — all meaning the same thing, but treated as different values. We often clean text to prepare for structured work like pivot tables or visualizations.
In this section, we’ll learn how to change the case of text, remove unwanted spaces, and simplify messy entries.
Make text lowercase, uppercase, or title case
Excel
In Excel, you use =LOWER()
, =UPPER()
, or =PROPER()
to standardize how words are written.
t0 Prompt
Make all country names lowercase
Capitalize every word in the seller column
Change buyer names to uppercase
Code
The python code looks as follows:
Remove extra spaces
Excel
In Excel, you use =TRIM()
to remove extra spaces before, after, or between words.
t0 Prompt
Clean up spacing in the seller column
Remove leading and trailing spaces
Trim extra spaces from all text entries in column X
Code
The python code looks as follows:
Replace characters or punctuation
Excel
In Excel, you use =SUBSTITUTE()
or =REPLACE()
to clean or simplify characters in text.
t0 Prompt
Remove dots from the suffix column
Replace slashes with hyphens
Clean special characters from names
Code
The python code looks as follows:
Function | Description |
---|---|
str.lower() | Converts text to lowercase |
str.upper() | Converts text to uppercase |
str.title() | Capitalizes each word |
str.strip() | Removes leading and trailing spaces |
str.replace("x", "y") | Replaces specific characters or symbols |