Challenge - 5 Problems
String Accessor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of .str.upper() on a Series
What is the output of this code snippet?
Data Analysis Python
import pandas as pd s = pd.Series(['apple', 'Banana', 'Cherry']) result = s.str.upper() print(result)
Attempts:
2 left
💡 Hint
The .str.upper() method converts all characters in each string to uppercase.
✗ Incorrect
The .str.upper() method changes all letters in each string of the Series to uppercase. So all words become fully uppercase.
❓ data_output
intermediate2:00remaining
Count of strings containing 'a' using .str.contains()
Given the Series below, what is the count of strings that contain the letter 'a' (case insensitive)?
Data Analysis Python
import pandas as pd s = pd.Series(['Cat', 'dog', 'parrot', 'fish', 'ant']) count = s.str.contains('a', case=False).sum() print(count)
Attempts:
2 left
💡 Hint
Use .str.contains() with case=False to ignore letter case.
✗ Incorrect
The strings containing 'a' or 'A' are 'Cat', 'parrot', and 'ant', so count is 3.
🔧 Debug
advanced2:00remaining
Identify the error in .str.replace() usage
What error does this code raise?
Data Analysis Python
import pandas as pd s = pd.Series(['apple', 'banana', 'cherry']) result = s.str.replace('a', 1) print(result)
Attempts:
2 left
💡 Hint
Check the type of the replacement argument in .str.replace().
✗ Incorrect
The .str.replace() method expects the replacement to be a string, but 1 is an integer, causing a TypeError.
🧠 Conceptual
advanced2:00remaining
Behavior of .str.split() with n parameter
What is the output of this code?
Data Analysis Python
import pandas as pd s = pd.Series(['a,b,c', 'd,e,f', 'g,h,i']) result = s.str.split(',', n=1) print(result)
Attempts:
2 left
💡 Hint
The n parameter limits the number of splits from the left.
✗ Incorrect
With n=1, only the first comma is used to split each string, so the result is a list with two elements: before and after the first comma.
🚀 Application
expert3:00remaining
Extract domain names from email addresses
Given a Series of email addresses, which option correctly extracts the domain names (part after '@')?
Data Analysis Python
import pandas as pd emails = pd.Series(['alice@example.com', 'bob@test.org', 'carol@data.net']) domains = ??? print(domains)
Attempts:
2 left
💡 Hint
Use a method that splits the string at '@' and returns the part after it.
✗ Incorrect
The .str.partition('@')[2] returns the part after '@' correctly. Option A returns a Series of lists, not strings. Option A's regex misses dots in domain names. Option A uses replace with regex but without regex=True, so it fails.