1. Home
  2. Data Science
  3. Pandas
  4. What does pd.concat([a, b], keys=['x','y']) add to the…

Added 30 Nov -0001

What does pd.concat([a, b], keys=['x','y']) add to the result?

  1. Columns prefixed with x_ and y_, aligned on the shared index labels
  2. A dictionary of the two frames keyed by x and y instead of a frame
  3. A MultiIndex whose outer level records which frame each row came from Correct answer
  4. A new column named keys holding x or y for each contributing row of both

Correct answer

C. A MultiIndex whose outer level records which frame each row came from

13 views

MCQSEXAM

Explanation

The keys argument adds an outer level to the row index, so each block of rows is tagged with the key of the frame it came from; this is how concat builds a MultiIndex without a separate column. Passing names labels that new level, and axis=1 applies the keys to columns instead of rows. Use assign before concat when a plain column is wanted rather than an index level.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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