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
Pandas Clean, Merge, Aggregate
00:00
5 left

Pandas Clean, Merge, Aggregate

MediumSQL · PostgreSQL

Problem

Write a Python function using Pandas to clean, merge, and aggregate two disparate client datasets with mismatched timestamps.

For this SQL version, use the supplied client registry and two datasets. Exclude records missing timestamps or metric values, align valid records by calendar date, and preserve valid dataset records even when no registry match exists.

Output

  1. One row per client and event date.
  2. Return client_id, client_name, event_date, dataset_a_value, dataset_b_value, total_value, and total_events.
  3. Treat missing source values as zero, order by event_date ascending and client_id ascending.

Schema

client_registry
ColumnTypeDescription
client_idPKINTCanonical client identifier
client_nameVARCHAR(100)Client display name
client_dataset_a
ColumnTypeDescription
record_idPKINTDataset A record identifier
client_idINTClient identifier from dataset A
recorded_atTIMESTAMPDataset A event timestamp
amountNUMERIC(12,2)Dataset A metric value
client_dataset_b
ColumnTypeDescription
observation_idPKINTDataset B record identifier
client_idINTClient identifier from dataset B
observed_atTIMESTAMPDataset B event timestamp
scoreNUMERIC(12,2)Dataset B metric value
Tablesclient_registryclient_dataset_aclient_dataset_b
Interviewer

Your question is Pandas Clean, Merge, Aggregate. Start with the requirements and the three 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.