Replace Null Values in Dataset Based on Column Data Type
Beginner Mode
Start your terminal to use beginner mode.
Scenario
A sales dataset contains missing values across different column types that need to be cleaned before analysis.
Task
Write a Python script at /home/interview/clean_sales.py using pandas that reads /home/interview/sales_data.csv, replaces null values based on column type (numeric columns with 0, text columns with "Unknown"), and saves the cleaned dataset to /home/interview/cleaned_data.csv.
Example
Input with nulls:
order_id,customer_name,quantity,status
1,John Doe,5,completed
2,,NaN,
3,Jane Smith,10,pending
Expected output:
order_id,customer_name,quantity,status
1,John Doe,5,completed
2,Unknown,0,Unknown
3,Jane Smith,10,pending
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
OpenAI