1. Home
  2. Data Science
  3. Pandas
  4. A pattern capturing one or more digits is applied with…

Added 30 Nov -0001

A pattern capturing one or more digits is applied with Series.str.extract to a column where some values do not match. What appears in those rows?

  1. NaN in the extracted column, because a non-match yields a missing value Correct answer
  2. An empty string, because extract returns the unmatched part of the input
  3. The original value unchanged, since extract only rewrites matching rows
  4. An error, because extract requires every value to match the pattern

Correct answer

A. NaN in the extracted column, because a non-match yields a missing value

18 views

MCQSEXAM

Explanation

str.extract returns one column per capture group and fills rows whose value does not match the pattern with NaN, so the result is a float or object column rather than a clean integer one. Pass expand=False to get a Series when there is a single group, and use contains or match with na=False when booleans are wanted. Non-string values are themselves treated as missing rather than raising.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

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