A 400-million-row DataFrame has a "country" column of 200 repeated strings and an "age" column stored as int64. Which change saves the most GPU memory with no information loss?
- Exam domain
- GPU and Cloud Computing16% of the exam
- Difficulty
- Hard
- In this mock
- 8 questions on this domainPractise this domain
Why the exam asks this
GPU and Cloud Computing (16% of the exam)
Objective in the exam guide: Determining the optimal data type choice for each feature
Data type choice appears in two domains.
Why A is the answer
Make country categorical and downcast age to int8
Categorical encoding stores each repeated string once plus small integer codes. Ages fit in int8, one eighth the size of int64.
Remember: Choose the smallest dtype that holds the data.
How it works
Choosing optimal dtypes per feature cuts memory and speeds processing.
In detail
- Categorical for repeated strings.
- Smallest numeric type that fits.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Make country categorical and downcast age to int8Right
Choose the smallest dtype that holds the data.
B. Store both as stringsWrong
Strings are the most expensive.
C. Duplicate the columns for safetyWrong
Duplicating doubles memory.
D. Convert age to float64 and country to a long free-text column for flexibilityWrongMost tempting
float64 and free text use more memory.
Why it tempts: Flexibility sounds valuable.
Use case
An illustrative scenario, not a real incident.
Illustrative: dtype changes shrink the DataFrame from 30 GB to 7 GB on the GPU.
See it in different ways
flowchart TD
Q{"Column content?"}
Q -->|"Few repeated strings"| A0["category"]
Q -->|"Small integers"| A1["int8 or int16"]
Q -->|"Decimals with modest precision"| A2["float32"]How to read this chart
- At "Column content?": if "Few repeated strings", go to "category"; if "Small integers", go to "int8 or int16"; if "Decimals with modest precision", go to "float32".
mindmap
root(("Data types"))
n1["Text"]
n2["category for repeats"]
n3["Integers"]
n4["int8 to int64"]
n5["Floats"]
n6["float32 vs float64"]
n7["Flags"]
n8["bool"]How to read this chart
- The centre is "Data types".
- "Text" covers "category for repeats".
- "Integers" covers "int8 to int64".
- "Floats" covers "float32 vs float64".
- "Flags" covers "bool".