What does pd.concat([a, b], keys=['x','y']) add to the result?
Correct answer
C. A MultiIndex whose outer level records which frame each row came from
13 views
C. A MultiIndex whose outer level records which frame each row came from
13 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.