0
0
Pandasdata~20 mins

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

Choose your learning style9 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.