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 in a pandas Series that contains text data, making it easy to manipulate text in columns.Click to reveal answer
beginner
How do you convert all text in a pandas Series to lowercase using
.str methods?Use
series.str.lower() to convert all characters in each string of the Series to lowercase.Click to reveal answer
beginner
What does
series.str.contains('abc') do?It checks each string in the Series to see if it contains the substring 'abc' and returns a Series of True or False values.
Click to reveal answer
beginner
How can you extract the first 3 characters from each string in a pandas Series?
Use
series.str[:3] to slice the first three characters from each string in the Series.Click to reveal answer
beginner
What will
series.str.replace('a', 'x') do?It replaces every occurrence of the letter 'a' with 'x' in each string of the Series.
Click to reveal answer
Which pandas method would you use to check if strings in a Series start with 'Hello'?
✗ Incorrect
The
startswith() method checks if each string starts exactly with the given substring.What does
series.str.len() return?✗ Incorrect
str.len() returns a Series with the length of each string element.How do you remove whitespace from the start and end of strings in a Series?
✗ Incorrect
str.strip() removes whitespace from both ends of each string.Which method splits strings in a Series by a delimiter?
✗ Incorrect
str.split() splits each string into a list using the delimiter.What type of object is returned by
series.str.extract(r'(\d+)')?✗ Incorrect
str.extract() returns a DataFrame with the matched groups from the regex.Explain how the
.str accessor helps when working with text data in pandas Series.Think about how you would handle text in many rows at once.
You got /3 concepts.
Describe three common string operations you can perform using pandas
.str methods.Consider operations useful for cleaning or analyzing text.
You got /3 concepts.