Why is csv.DictReader often easier to maintain than csv.reader?
- It skips rows with missing values automatically
- It allows access by column name instead of numeric index
- It always uses less memory than
csv.reader - It converts strings into numbers automatically
Answer: 2 Type: single Time: 40 Explanation: Column-name access makes code clearer and reduces index mistakes.
Given movie = {"music_by": ""}, which check correctly treats the field as missing?
if movie["music_by"] is None:if movie["music_by"] == 0:if movie["music_by"].strip() == "":if len(movie["music_by"]) > 0:
Answer: 3
Type: single
Time: 40
Explanation: In CSV-style data cleaning, missing values are often empty strings, so stripping and comparing to "" is reliable.
Which pattern best describes a basic cleaning workflow?
- Read -> train model -> deploy
- Detect missing values -> update/fix -> validate -> save
- Sort -> reverse -> deduplicate only
- Compress -> encrypt -> upload
Answer: 2 Type: single Time: 40 Explanation: Practical cleaning typically includes detection, correction, verification, and writing cleaned output.
What does this line do?
movie["music_by"] = "Joe Hisaishi"
- Deletes a key from the dictionary
- Creates or updates the
music_byvalue - Converts the whole dictionary to CSV
- Appends a new dictionary to a list
Answer: 2 Type: single Time: 35 Explanation: Dictionary assignment updates an existing key or creates it if missing.
When writing cleaned rows to CSV with DictWriter, which steps are required?
- Create
DictWriterwithfieldnames - Call
writeheader() - Call
writerows(rows) - Use
json.dumpin the same file handle
Answer: 1,2,3
Type: multiple
Time: 45
Explanation: DictWriter needs field names, then header writing, then row writing. json.dump is unrelated to CSV output.
If your script loops through all n rows once to detect missing values, what is the time complexity?
- O(1)
- O(log n)
- O(n)
- O(n^2)
Answer: 3 Type: single Time: 35 Explanation: A single full pass over rows is linear time.
If your script stores all cleaned rows in a list before saving, what is the extra space complexity with respect to rows?
- O(1)
- O(log n)
- O(n)
- O(n^2)
Answer: 3 Type: single Time: 35 Explanation: Keeping all rows in memory grows linearly with dataset size.
Why is saving cleaned data to a new file often better than overwriting the raw input immediately?
- It is always faster
- It preserves the original data for audit and rollback
- It removes the need for validation
- It guarantees perfect cleaning
Answer: 2 Type: single Time: 40 Explanation: Keeping raw data intact makes debugging and verification safer.
Which statements about dictionary/list cleaning code are true?
for row in rows:iterates one dictionary per rowrow["year"] = "1989"updates the current rowbreakcan stop at the first matchint(row["year"])is always safe without checks
Answer: 1,2,3
Type: multiple
Time: 45
Explanation: The first three are core loop behaviors; converting to int is unsafe if values are missing or non-numeric.
Which strategy is best before computing an average from CSV text values?
- Convert every value with
int()directly without checks - Skip conversion and average strings
- Validate/clean values first, then convert numeric fields
- Sort rows alphabetically first
Answer: 3 Type: single Time: 40 Explanation: Numeric statistics should be computed only after missing/invalid values are handled.