str.upper() behaves exactly like str.lower(), but converts to uppercase instead — both are simple case-normalization operations, vectorized across the whole Series and automatically skipping NaN values rather than raising an error on them. It's commonly used for generating display-formatted codes or identifiers, like country codes or product SKUs, that are conventionally shown in all caps.
1Understanding Series.str.upper()
str.upper() behaves exactly like str.lower(), but converts to uppercase instead — both are simple case-normalization operations, vectorized across the whole Series and automatically skipping NaN values rather than raising an error on them. It's commonly used for generating display-formatted codes or identifiers, like country codes or product SKUs, that are conventionally shown in all caps.
Like str.lower(), str.upper() automatically skips NaN values rather than raising an error on them — you don't need to filter out missing values separately before applying it.
import pandas as pd
s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())2Practical Example
Here is a real-world application of Series.str.upper() showing how it is used in production Pandas code.
import pandas as pd
df = pd.DataFrame({"code": [" us ", "Ca", "mx "]})
df["code"] = df["code"].str.strip().str.upper()
print(df)3Best Practices
Follow these guidelines when working with Series.str.upper():
1. Use str.upper() for display formatting of codes/identifiers that are conventionally shown in all caps, like country or currency codes
2. Combine str.upper() with str.strip() to normalize inconsistent-case, whitespace-padded codes in one pipeline
3. Reach for str.casefold() instead of str.upper()/str.lower() specifically for robust, locale-aware case-insensitive comparison beyond simple ASCII text
Tip: Like str.lower(), str.upper() automatically skips NaN values rather than raising an error on them — you don't need to filter out missing values separately before applying it.
import pandas as pd
s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())