1. Home
  2. Data Science
  3. Pandas
  4. pd.merge(a, b, on='id', validate='one_to_one') raises a…

Added 30 Nov -0001

pd.merge(a, b, on='id', validate='one_to_one') raises a MergeError. What does that tell you?

  1. The two frames hold different row counts, which the validation step forbids
  2. The key columns have different dtypes, so pandas cannot compare their values at all
  3. The merge produced more columns than expected, exceeding the validation threshold
  4. At least one side repeats a key value, so the join would produce duplicate rows Correct answer

Correct answer

D. At least one side repeats a key value, so the join would produce duplicate rows

14 views

MCQSEXAM

Explanation

Merge validation checks the cardinality of the join keys, so 'one_to_one' fails when either frame repeats a key, which would otherwise multiply rows silently. The other settings are 'one_to_many', 'many_to_one' and 'many_to_many'. It is the quickest guard against the fan-out bug that inflates totals after a join.

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