Which column type choice reduces memory for a "status" column with values active, paused and closed across 1 billion rows?
- Exam domain
- MLOps19% of the exam
- Difficulty
- Medium
- In this mock
- 10 questions on this domainPractise this domain
Why the exam asks this
Objective in the exam guide: Determining the optimal data type choice for each feature
Data type choice is listed under MLOps too.
Why D is the answer
Categorical dtype
Categorical stores three strings once and small integer codes per row, far smaller than repeated strings.
Remember: Low-cardinality text: categorical.
How it works
Choosing optimal dtypes per feature controls memory use in production pipelines.
In detail
- Categorical for low-cardinality text.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Free-text strings with full words repeated a billion times for readabilityWrong
Repeated strings use the most memory.
B. float64 codesWrong
float64 codes waste space.
C. One-hot encode into three float64 columnsWrongMost tempting
Three float64 columns are larger still.
Why it tempts: One-hot sounds model-ready.
D. Categorical dtypeRight
Low-cardinality text: categorical.
Use case
An illustrative scenario, not a real incident.
Illustrative: categorical cuts the column from about 7 GB to about 1 GB.
See it in different ways
flowchart TD
Q{"How many distinct values?"}
Q -->|"Few"| A0["Categorical"]
Q -->|"Mostly unique"| A1["String"]How to read this chart
- At "How many distinct values?": if "Few", go to "Categorical"; if "Mostly unique", go to "String".
mindmap
root(("Memory"))
n1["category"]
n2["Codes plus dictionary"]
n3["int8"]
n4["1 byte"]
n5["float32"]
n6["4 bytes"]How to read this chart
- The centre is "Memory".
- "category" covers "Codes plus dictionary".
- "int8" covers "1 byte".
- "float32" covers "4 bytes".