What does pd.to_numeric(s, errors='coerce') do with entries that cannot be parsed?
Correct answer
B. It replaces them with NaN and returns a numeric dtype column
14 views
B. It replaces them with NaN and returns a numeric dtype column
14 views
Coercion is the middle ground between errors='raise', which throws, and errors='ignore', which returns the input unchanged and can leave a mixed object column. Coerce turns unparseable entries into NaN, producing a float or nullable numeric dtype suitable for arithmetic. Count the new NaNs afterwards, because coercion can hide genuinely malformed data.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.