Bird
Raised Fist0
Pandasdata~20 mins

str.lower() and str.upper() in Pandas - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
String Case Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of converting pandas Series to lowercase
What is the output of this code snippet?
Pandas
import pandas as pd
s = pd.Series(['Apple', 'Banana', 'Cherry'])
result = s.str.lower()
print(result)
A
0     apple
1    banana
2    cherry
dtype: object
B['apple', 'banana', 'cherry']
C
0     APPLE
1    BANANA
2    CHERRY
dtype: object
D['APPLE', 'BANANA', 'CHERRY']
Attempts:
2 left
💡 Hint
Use str.lower() to convert all strings in the Series to lowercase.
❓ data_output
intermediate
2:00remaining
Count uppercase strings in a pandas Series
Given the Series below, how many strings are fully uppercase?
Pandas
import pandas as pd
s = pd.Series(['dog', 'CAT', 'Bird', 'FISH'])
upper_s = s.str.upper()
count_upper = sum(upper_s == s)
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
Compare the original Series with the uppercase version to find matches.
🔧 Debug
advanced
2:00remaining
Identify the error in using str.lower() on a DataFrame column
What error does this code raise?
Pandas
import pandas as pd
df = pd.DataFrame({'Name': ['Alice', 'Bob', 'CHARLIE']})
df['Name_lower'] = df['Name'].lower()
ATypeError: lower() takes no arguments (1 given)
BNo error, works fine
CAttributeError: 'Series' object has no attribute 'lower'
DKeyError: 'lower'
Attempts:
2 left
💡 Hint
Check if the pandas Series supports the lower() method directly.
🚀 Application
advanced
2:00remaining
Filter DataFrame rows with uppercase names
Which code correctly filters rows where the 'Name' column is fully uppercase?
Pandas
import pandas as pd
df = pd.DataFrame({'Name': ['ALICE', 'Bob', 'CHARLIE', 'dave']})
Adf[df['Name'].str.lower() == df['Name']]
Bdf[df['Name'] == df['Name'].str.upper()]
Cdf[df['Name'].str.upper() == 'NAME']
Ddf[df['Name'].str.isupper()]
Attempts:
2 left
💡 Hint
Use a string method that checks if all characters are uppercase.
🧠 Conceptual
expert
2:00remaining
Understanding behavior of str.upper() with missing values
What is the output of this code?
Pandas
import pandas as pd
s = pd.Series(['hello', None, 'WORLD'])
result = s.str.upper()
print(result)
A
0    HELLO
1     NaN
2    WORLD
dtype: object
BRaises TypeError due to None value
C
0    HELLO
1    NAN
2    WORLD
dtype: object
D
0    HELLO
1     None
2    WORLD
dtype: object
Attempts:
2 left
💡 Hint
Check how pandas handles None values in string operations.

Practice

(1/5)
1. What does the pandas method str.lower() do when applied to a Series of text data?
easy
A. Converts all characters in the text to lowercase.
B. Converts all characters in the text to uppercase.
C. Removes all spaces from the text.
D. Reverses the order of characters in the text.

Solution

  1. Step 1: Understand the method purpose

    The str.lower() method changes all letters in text to lowercase.
  2. Step 2: Compare with other options

    Other options describe different actions like uppercase, removing spaces, or reversing text, which are not what str.lower() does.
  3. Final Answer:

    Converts all characters in the text to lowercase. -> Option A
  4. Quick Check:

    str.lower() = lowercase conversion [OK]
Hint: Lowercase means all letters small [OK]
Common Mistakes:
  • Confusing str.lower() with str.upper()
  • Thinking it removes spaces
  • Assuming it reverses text
2. Which of the following is the correct way to convert a pandas Series named names to uppercase?
easy
A. names.str.upper()
B. str.upper(names)
C. names.upper()
D. names.str.upper

Solution

  1. Step 1: Recall pandas string method syntax

    To apply string methods on a pandas Series, use Series.str.method() syntax.
  2. Step 2: Check each option

    names.str.upper() uses names.str.upper(), which is correct. names.upper() misses .str, str.upper(names) is incorrect function call, names.str.upper misses parentheses.
  3. Final Answer:

    names.str.upper() -> Option A
  4. Quick Check:

    Use .str.upper() on Series [OK]
Hint: Use .str before string methods on Series [OK]
Common Mistakes:
  • Calling upper() directly on Series without .str
  • Forgetting parentheses after method
  • Using str.upper() as a standalone function
3. Given the pandas Series data = pd.Series(['Apple', 'Banana', 'Cherry']), what is the output of data.str.lower()?
medium
A. ['Apple', 'Banana', 'Cherry']
B. ['APPLE', 'BANANA', 'CHERRY']
C. ['apple', 'banana', 'cherry']
D. ['aPPLE', 'bANANA', 'cHERRY']

Solution

  1. Step 1: Understand the input Series

    The Series contains capitalized fruit names: 'Apple', 'Banana', 'Cherry'.
  2. Step 2: Apply str.lower() method

    This method converts all letters to lowercase, so each word becomes fully lowercase.
  3. Final Answer:

    ['apple', 'banana', 'cherry'] -> Option C
  4. Quick Check:

    str.lower() makes all letters lowercase [OK]
Hint: str.lower() makes all letters small [OK]
Common Mistakes:
  • Expecting original case to remain
  • Confusing with str.upper() output
  • Thinking only first letter changes
4. What is wrong with this code snippet to convert a pandas Series cities to uppercase?
cities = pd.Series(['Paris', 'London', 'Berlin'])
cities_upper = cities.upper()
medium
A. Missing import statement for pandas.
B. The code should use cities.upper without parentheses.
C. Series cannot be converted to uppercase.
D. Method upper() should be called as cities.str.upper().

Solution

  1. Step 1: Identify method usage on Series

    String methods like upper() must be called with .str accessor on pandas Series.
  2. Step 2: Check the code

    The code uses cities.upper() which is invalid; correct is cities.str.upper().
  3. Final Answer:

    Method upper() should be called as cities.str.upper(). -> Option D
  4. Quick Check:

    Use .str.upper() on Series [OK]
Hint: Use .str before string methods on Series [OK]
Common Mistakes:
  • Calling upper() directly on Series
  • Forgetting .str accessor
  • Removing parentheses from method call
5. You have a pandas DataFrame df with a column 'Product' containing mixed case product names. You want to create a new column 'Product_Upper' with all names in uppercase. Which code correctly does this?
hard
A. df['Product_Upper'] = df['Product'].upper()
B. df['Product_Upper'] = df['Product'].str.upper()
C. df['Product_Upper'] = str.upper(df['Product'])
D. df['Product_Upper'] = df['Product'].str.lower()

Solution

  1. Step 1: Understand the DataFrame and goal

    The goal is to create a new column with uppercase product names from an existing column.
  2. Step 2: Apply correct method for uppercase conversion

    Use .str.upper() on the Series to convert text to uppercase correctly.
  3. Step 3: Check options

    df['Product_Upper'] = df['Product'].str.upper() uses correct syntax. df['Product_Upper'] = df['Product'].upper() misses .str, df['Product_Upper'] = str.upper(df['Product']) uses wrong function call, df['Product_Upper'] = df['Product'].str.lower() converts to lowercase, not uppercase.
  4. Final Answer:

    df['Product_Upper'] = df['Product'].str.upper() -> Option B
  5. Quick Check:

    Use .str.upper() to uppercase Series text [OK]
Hint: Use .str.upper() to convert Series text uppercase [OK]
Common Mistakes:
  • Calling upper() without .str
  • Using str.upper() as a function on Series
  • Confusing upper() with lower()
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard