1. Home
  2. Data Science
  3. Pandas
  4. A DataFrame has a column tags whose values are lists of…

Added 30 Nov -0001

A DataFrame has a column tags whose values are lists of strings. What does df.explode(tags) do?

  1. It splits each string on commas into separate columns, one per element
  2. It flattens the whole column into a single Series of concatenated list values
  3. It expands the lists into new columns named tags_0, tags_1 and so on
  4. It gives each list element its own row, repeating the other column values Correct answer

Correct answer

D. It gives each list element its own row, repeating the other column values

11 views

MCQSEXAM

Explanation

explode converts a list-like entry into one row per element, duplicating the remaining column values and reusing the original index label. It is the inverse of the groupby-agg-list pattern, not of pivot: to widen a column of lists you need to build the columns yourself. An empty list produces a NaN row rather than disappearing, which is a frequent surprise when counting rows afterwards.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs