A. Using 'int8' may cause overflow if values exceed range
B. memory_usage() does not show memory savings
C. astype cannot convert columns after reading CSV
D. No error; code correctly reduces memory usage
Solution
Step 1: Check int8 range suitability
int8 supports values from -128 to 127; larger values cause overflow.
Step 2: Identify potential overflow risk
If 'num_col' has values outside int8 range, conversion causes incorrect data.
Final Answer:
Using 'int8' may cause overflow if values exceed range -> Option A
Quick Check:
int8 range limits can cause data errors [OK]
Hint: Check numeric ranges before downcasting to smaller types [OK]
Common Mistakes:
Assuming all int conversions are safe
Believing memory_usage() ignores changes
Thinking astype fails after CSV read
5. You have a large dataset with a column 'status' containing only three unique string values repeated many times. Which memory-efficient approach is best to reduce memory usage and why?
Options:
A) Drop the 'status' column to save memory.
B) Convert 'status' to string type and keep numeric columns as float64.
C) Convert 'status' to category type and downcast numeric columns to smallest possible integer type.
D) Convert all columns to object type for flexibility.
hard
A. Drop the 'status' column to save memory.
B. Convert 'status' to category type and downcast numeric columns to smallest possible integer type.
C. Convert 'status' to string type and keep numeric columns as float64.
D. Convert all columns to object type for flexibility.
Solution
Step 1: Use category for repeated strings
Converting 'status' to category stores unique values once, saving memory.
Step 2: Downcast numeric columns
Downcasting numeric columns to smallest integer type reduces memory without losing data.
Step 3: Evaluate other options
Keeping strings as object or dropping columns wastes memory or data; object type uses more memory.
Final Answer:
Convert 'status' to category type and downcast numeric columns to smallest possible integer type. -> Option B
Quick Check:
Category + downcast = best memory saving [OK]
Hint: Use category for repeated strings and downcast numbers [OK]
Common Mistakes:
Dropping useful columns unnecessarily
Keeping strings as object wastes memory
Converting all to object increases memory
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.