0
0
Data Analysis Pythondata~5 mins

String accessor (.str) methods in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
Aseries.str.contains('Hello')
Bseries.str.match('Hello')
Cseries.str.find('Hello')
Dseries.str.startswith('Hello')
What does series.str.len() return?
AThe length of each string in the Series
BThe total number of strings in the Series
CThe number of unique strings
DThe number of missing values
How do you remove whitespace from the start and end of strings in a Series?
Aseries.str.remove()
Bseries.str.trim()
Cseries.str.strip()
Dseries.str.clean()
Which method splits strings in a Series by a delimiter?
Aseries.str.split(',')
Bseries.str.divide(',')
Cseries.str.cut(',')
Dseries.str.partition(',')
What type of object is returned by series.str.extract(r'(\d+)')?
AA Series of booleans
BA DataFrame with extracted groups
CA list of strings
DAn integer count
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.