Recall & Review
beginner
What is the purpose of the
str accessor in pandas?The
str accessor allows you to apply string methods to each element of a pandas Series that contains text data, making it easy to manipulate strings in a column.Click to reveal answer
beginner
How do you convert all text in a pandas Series to lowercase using the
str accessor?Use
series.str.lower() to convert all strings in the Series to lowercase letters.Click to reveal answer
beginner
What will
series.str.contains('apple') return?It returns a Series of boolean values indicating whether each string in the Series contains the substring 'apple'.
Click to reveal answer
intermediate
Can you chain multiple string methods using the
str accessor? Give an example.Yes, you can chain methods like
series.str.strip().str.upper() to first remove whitespace and then convert text to uppercase.Click to reveal answer
intermediate
What happens if you use a string method with
str accessor on a Series with missing (NaN) values?The string methods safely handle missing values by returning
NaN for those entries without causing errors.Click to reveal answer
Which pandas code converts all strings in a Series
names to uppercase?✗ Incorrect
The
str accessor is needed to apply string methods element-wise on a Series.What does
series.str.len() return?✗ Incorrect
It returns a Series with the length of each string element.
How do you check if strings in a Series start with 'data'?
✗ Incorrect
The
str.startswith() method checks the start of each string.If a Series has missing values, what does
series.str.lower() do to those?✗ Incorrect
Missing values remain
NaN and do not cause errors.Which method removes whitespace from the start and end of strings in a Series?
✗ Incorrect
The
str.strip() method removes leading and trailing whitespace.Explain how the
str accessor helps when working with text data in pandas Series.Think about how you would clean or search text in a list of words.
You got /4 concepts.
Describe a real-life example where you might use
series.str.contains() in data analysis.Imagine you have a list of product names and want to find all that mention 'organic'.
You got /4 concepts.