Why might this cause an error or unexpected behavior?
medium
A. Converting numeric to category without checking unique values may increase memory usage or cause unexpected behavior.
B. You cannot convert a column twice in pandas.
C. astype('category') only works on string columns.
D. int64 is not a valid dtype in pandas.
Solution
Step 1: Understand dtype conversion to category
Converting numeric to category is allowed but categories are based on unique values.
Step 2: Consider memory and behavior risks
If the numeric column has many unique values, category conversion may increase memory or cause unexpected grouping.
Final Answer:
Converting numeric to category without checking unique values may increase memory usage or cause unexpected behavior. -> Option A
Quick Check:
Category dtype needs careful unique value check [OK]
Hint: Check unique values before converting to category [OK]
Common Mistakes:
Thinking multiple astype() calls are invalid
Believing astype('category') only works on strings
Assuming int64 is invalid dtype
5. You have a large DataFrame with a column status containing only three unique string values: 'new', 'in_progress', 'done'. Which dtype change will save memory and keep data efficient?
hard
A. Keep status as string without changes.
B. Convert status to object dtype.
C. Convert status to int64 dtype directly.
D. Convert status to category dtype.
Solution
Step 1: Identify unique values in 'status'
Only three unique strings exist, ideal for categorical dtype.
Step 2: Understand category dtype benefits
Category stores unique values once and uses integer codes internally, saving memory.
Step 3: Compare other options
Object dtype stores full strings repeatedly; int64 conversion is invalid without mapping; no change wastes memory.
Final Answer:
Convert status to category dtype. -> Option D
Quick Check:
Few unique strings? Use category dtype [OK]
Hint: Few unique strings? Use category dtype for memory [OK]
Common Mistakes:
Trying to convert strings directly to int64 without mapping
Keeping object dtype wastes memory
Ignoring category dtype benefits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.