Functions
Text
UPPER
How to Use Excel's UPPER Function in Pandas
Excel's UPPER function is used to change all letters in a given text to uppercase. This function can be particularly useful for normalizing data entries or ensuring data consistency before merging or grouping data.
This page explains how to use Excel's UPPER function in Python using pandas.
Use Mito's UPPER function
Mito is an open source library that lets you write Excel formulas in Python. Either write the formula directly in Python or use the UPPER formula in the Mito Spreadsheet and generate the equivalent Python code automatically.
Mito's UPPER function works exactly like it does in Excel. That means you don't need worry about managing data types, handling errors, or the edge case differences between Excel and Python formulas.
Install Mito to start using Excel formulas in Python.
# Import the mitosheet Excel functions
from mitosheet.public.v3 import *;
# Use Mito's UPPER function
df['name'] = UPPER(df['name'])
Implementing the Convert String to Uppercase function in Pandas#
To replicate the UPPER function in Excel using Python and pandas, you can utilize the `.str.upper()` method. Here's how you can use it:
Convert a Column to Uppercase#
In Excel, you would use the UPPER function on each cell of a column to convert the entire column's text to uppercase.
In pandas, to achieve the same effect, apply the `.str.upper()` method to the desired column. The following code demonstrates how to convert the 'name' column to uppercase:
df['name'] = df['name'].str.upper()
Common mistakes when using UPPER in Python#
When using the `.str.upper()` method in pandas to replicate Excel's UPPER function, the most common source of error is forgetting to use the `.str` accessor.
Not Using .str Accessor#
A frequent oversight is forgetting to use the `.str` accessor before applying string functions to a pandas Series.
If you mistakenly use `df['column'].upper()` instead of the correct `df['column'].str.upper()`, you'll encounter an AttributeError.
# Incorrect approach
df['column'].upper()
# Correct approach
df['column'].str.upper()
Understanding the Convert String to Uppercase Formula in Excel#
The UPPER function in Excel requires only one argument: the text you want to convert to uppercase.
=UPPER(text)
UPPER Excel Syntax
Parameter | Description | Data Type |
---|---|---|
text | The text you want to convert to uppercase. | string |
Examples
Formula | Description | Result |
---|---|---|
=UPPER("hello") | Converts the word 'hello' to uppercase. | HELLO |
Don't re-invent the wheel. Use Excel formulas in Python.
Install MitoDon't want to re-implement Excel's functionality in Python?
Edit a spreadsheet.
Generate Python.
Mito is the easiest way to write Excel formulas in Python. Every edit you make in the Mito spreadsheet is automatically converted to Python code.
View all 100+ transformations →