0
0
Pandasdata~5 mins

str.split() for splitting in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the str.split() method do in pandas?
It splits each string in a pandas Series or DataFrame column into parts based on a separator, returning a list or expanding into multiple columns.
Click to reveal answer
beginner
How do you split a pandas Series column into multiple columns using str.split()?
Use str.split(pat, expand=True). The expand=True makes the split parts become separate columns.
Click to reveal answer
beginner
What is the default separator for str.split() in pandas?
The default separator is any whitespace (spaces, tabs, newlines).
Click to reveal answer
intermediate
How can you limit the number of splits when using str.split()?
Use the n parameter to specify the maximum number of splits to do from the left.
Click to reveal answer
beginner
What happens if you use str.split() without expand=True?
The result is a Series of lists, where each list contains the split parts of the original string.
Click to reveal answer
What does expand=True do in str.split()?
ARemoves whitespace
BLimits the number of splits
CReturns split parts as separate columns
DChanges the separator
What is the default separator used by str.split() in pandas?
AWhitespace
BComma (",")
CSemicolon (";")
DNo separator
If you want to split a string only once from the left, which parameter do you use?
Acount=1
Bmaxsplit=1
Climit=1
Dn=1
What type of object does str.split() return by default?
ASeries of lists
BDataFrame
CList
DDictionary
Which of these is a correct way to split a pandas Series column named 'Name' by comma and expand into columns?
Adf.str.split('Name', ',', expand=True)
Bdf['Name'].str.split(',', expand=True)
Cdf['Name'].split(',', expand=True)
Ddf['Name'].split(',')
Explain how to split a pandas Series column into multiple columns using str.split().
Think about how to turn one column with strings into several columns.
You got /3 concepts.
    Describe the difference in output when using str.split() with and without expand=True.
    Consider the shape and type of the output.
    You got /3 concepts.