🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpandas

pandas Documentation

LOADING ENGINE...

Series.str.upper()

AI & DATA SCIENCE // series-str-upper

series.str.upper() converts every string in a Series to uppercase, the direct counterpart to str.lower().

Syntax

series.str.upper()

Deep Dive Course

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.

editor.html
import pandas as pd

s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())
localhost:3000

2Practical Example

Here is a real-world application of Series.str.upper() showing how it is used in production Pandas code.

editor.html
import pandas as pd

df = pd.DataFrame({"code": [" us ", "Ca", "mx "]})
df["code"] = df["code"].str.strip().str.upper()
print(df)
localhost:3000

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.

editor.html
import pandas as pd

s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())
localhost:3000

Examples

Example 01Basic Usage
import pandas as pd

s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())
Example 02Advanced Example
import pandas as pd

df = pd.DataFrame({"code": [" us ", "Ca", "mx "]})
df["code"] = df["code"].str.strip().str.upper()
print(df)

Best Practices

  • Use str.upper() for display formatting of codes/identifiers that are conventionally shown in all caps, like country or currency codes
  • Combine str.upper() with str.strip() to normalize inconsistent-case, whitespace-padded codes in one pipeline
  • Reach for str.casefold() instead of str.upper()/str.lower() specifically for robust, locale-aware case-insensitive comparison beyond simple ASCII text

Interview Question

Why does chaining str.strip() and str.upper() work correctly on a Series, calling two string methods back to back?

Hint: Think about what each .str method call actually returns.

Each .str method call, like str.strip(), returns a brand-new Series with the transformation already applied, and that returned Series still has the .str accessor available on it, since it's still a Series of strings. This is exactly what allows chaining: str.strip() first produces a whitespace-trimmed Series, and calling str.upper() directly on that result then uppercases the already-trimmed values, applying both transformations in sequence within a single, readable expression.

Exercises

MediumPractice using Series.str.upper() in a real scenario.
View Solution
import pandas as pd

s = pd.Series(["usd", "eur", "gbp"])
print(s.str.upper())

Frequently Asked Questions

Why does chaining str.strip() and str.upper() work correctly on a Series, calling two string methods back to back?

Each .str method call, like str.strip(), returns a brand-new Series with the transformation already applied, and that returned Series still has the .str accessor available on it, since it's still a Series of strings. This is exactly what allows chaining: str.strip() first produces a whitespace-trimmed Series, and calling str.upper() directly on that result then uppercases the already-trimmed values, applying both transformations in sequence within a single, readable expression.

Related Functions

series-str-lowerseries-str-replaceseries-str-len