Two columns use "N/A", "", and "-" for missing values, and pandas reads them as strings. What should the preprocessing do?
- Exam domain
- Data Preparation17% of the exam
- Difficulty
- Medium
- In this mock
- 8 questions on this domainPractise this domain
Why the exam asks this
Data Preparation (17% of the exam)
Objective in the exam guide: Performing data cleansing and preprocessing using CuDF and pandas
Cleansing is the first preparation objective.
Why B is the answer
Map those markers to nulls when reading, then convert to numeric
Mapping all missing markers to proper nulls lets the column be numeric and missing values be handled deliberately.
Remember: Map missing markers to nulls, then cast.
How it works
Preprocessing normalizes missing markers and types before analysis.
In detail
- Normalize missing markers.
- Cast to the right type.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Drop both columnsWrong
Dropping loses the feature.
B. Map those markers to nulls when reading, then convert to numericRight
Map missing markers to nulls, then cast.
C. Leave them as strings so no information about the original formatting is lost in processingWrong
String columns block numeric use.
D. Replace them with zero everywhereWrongMost tempting
Zero is a value, not missing.
Why it tempts: Zero feels like a safe default.
Use case
An illustrative scenario, not a real incident.
Illustrative: setting na_values on read turns a string column back into float.
See it in different ways
flowchart LR S0["List markers"] --> S1["Map to null on read"] --> S2["Cast to numeric"] --> S3["Decide fill strategy"]
How to read this chart
- Read it in order: List markers, then Map to null on read, then Cast to numeric, then Decide fill strategy.
flowchart TD
Q{"Contains placeholder markers?"}
Q -->|"Yes"| A0["Map to null and cast"]
Q -->|"No"| A1["Check for stray characters"]How to read this chart
- At "Contains placeholder markers?": if "Yes", go to "Map to null and cast"; if "No", go to "Check for stray characters".