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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Structuring and Cleaning for Prediction
00:00
5 left

Structuring and Cleaning for Prediction

MediumSQL · PostgreSQL

Problem

Given a raw dataset, how would you structure and clean it for a predictive model?

Use the provided encounter and facility data. Retain the newest record for each encounter, exclude records with missing required dates or invalid facility references, normalize payer and age fields, and preserve missingness indicators where appropriate.

Output

  1. One row per valid encounter with the columns listed in the output schema.
  2. Include normalized patient, facility, age, payer, length-of-stay, and readmission fields.
  3. Order by admission timestamp ascending, then encounter ID ascending.

Schema

raw_encounters
ColumnTypeDescription
raw_idPKINTUnique raw ingestion row identifier
encounter_idVARCHAR(20)Business identifier for the encounter
facility_codeVARCHAR(10)Raw facility identifier
patient_idVARCHAR(20)Patient identifier
admitted_atTIMESTAMPAdmission timestamp
discharge_atTIMESTAMPDischarge timestamp
age_textVARCHAR(10)Age as received in the raw extract
payer_textVARCHAR(40)Unstandardized payer label
length_of_stay_textVARCHAR(10)Raw length of stay value
readmission_30dBOOLEANThirty-day readmission target
ingested_atTIMESTAMPTimestamp when the raw row was ingested
facility_reference
ColumnTypeDescription
facility_codePKVARCHAR(10)Validated facility identifier
facility_nameVARCHAR(100)Facility name
regionVARCHAR(40)Facility operating region
Tablesraw_encountersfacility_reference
Interviewer

Your question is Structuring and Cleaning for Prediction. Start with the requirements and the two tables 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.