Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Parse and Clean Noisy CSV
00:00
5 left

Parse and Clean Noisy CSV

HardPython

Problem

Write a Python script to efficiently parse and clean a massive, noisy CSV file generated by an industrial sensor for Ametek.

Implement clean_sensor_csv(lines), where lines is an iterable of CSV text lines whose first nonblank line is the header timestamp,sensor_id,value,status. Return a list of dictionaries with stripped timestamp, stripped sensor_id, finite floating-point value, and uppercase status. Ignore blank lines, malformed CSV rows, rows with anything other than four fields, missing required fields, invalid numbers, and nonfinite values.

Example: ['timestamp,sensor_id,value,status ', '2026-01-01T00:00:00Z, S-17, 21.5, ok '] returns [{'timestamp': '2026-01-01T00:00:00Z', 'sensor_id': 'S-17', 'value': 21.5, 'status': 'OK'}]. Process the input in one pass using standard-library Python tools.

Constraints

  • lines is an iterable of strings.
  • The first nonblank line is the CSV header.
  • Each valid data row has exactly four fields in the order timestamp,sensor_id,value,status.
  • Input lines may be noisy, malformed, blank, or contain invalid numeric values.
  • The algorithm should process the input in one pass.
  • Use only Python standard-library modules.

Function Signature

def clean_sensor_csv(lines):
Interviewer

Your question is Parse and Clean Noisy CSV. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.