A. expand=True should be False to assign multiple columns.
B. The split separator ',' is incorrect for splitting locations.
C. You cannot assign multiple columns using a tuple as column names like ('City', 'State').
D. The code is correct and will work without errors.
Solution
Step 1: Check assignment syntax for multiple columns
Assigning multiple columns requires a list of column names, not a tuple.
Step 2: Identify correct syntax
Use df[['City', 'State']] = ... with double brackets for multiple columns.
Final Answer:
You cannot assign multiple columns using a tuple as column names like ('City', 'State'). -> Option C
Quick Check:
Use double brackets for multiple columns [OK]
Hint: Use double brackets [[]] to assign multiple columns [OK]
Common Mistakes:
Using single brackets with tuple for multiple columns
Confusing expand=True with assignment syntax
Assuming tuple works like list for columns
5. You have a DataFrame with a column 'Tags' containing strings like 'red,blue,green'. You want to create a new DataFrame where each tag is a separate row linked to the original row index. Which pandas method combined with str.split() helps achieve this?
hard
A. Use str.split(',', expand=True) to create multiple columns.
B. Use str.split(',').explode() to split and expand tags into rows.
C. Use str.split(',').apply(list) to convert tags to lists.
D. Use str.split(',').join() to merge tags back.
Solution
Step 1: Understand the goal to expand tags into rows
Splitting creates lists; explode() turns list elements into separate rows.
Step 2: Evaluate options for correct method
Use str.split(',').explode() to split and expand tags into rows. correctly chains str.split() with explode() to get one tag per row.
Final Answer:
Use str.split(',').explode() to split and expand tags into rows. -> Option B
Quick Check:
Split then explode = rows per item [OK]
Hint: Split then explode to get rows per list item [OK]
Common Mistakes:
Using expand=True creates columns, not rows
Forgetting to use explode() after split
Confusing join() with explode()
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.