Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Clean and Transform Disjoint Logs
00:00
5 left

Clean and Transform Disjoint Logs

HardSQL · PostgreSQL

Problem

Using Pandas, how would you clean, merge, and transform a dataset containing disjointed user activity logs?

Translate this data-wrangling task into PostgreSQL using the users and activity_logs tables. Normalize user identifiers and event labels, exclude unusable events, remove duplicate normalized records, and summarize activity by user and date.

Output

  1. One row per user and activity date, including users without valid activity.
  2. Return user_id, activity_date, total_events, active_minutes, and primary_activity.
  3. Sort by user_id, then activity_date ascending, with missing dates first.

Schema

users
ColumnTypeDescription
user_idPKINTCanonical user identifier
full_nameVARCHAR(100)User's full name
emailVARCHAR(255)Canonical user email address
activity_logs
ColumnTypeDescription
log_idPKINTActivity log identifier
user_emailVARCHAR(255)Raw user email from the activity source
event_timestampTIMESTAMPTimestamp when the activity occurred
event_typeVARCHAR(50)Raw activity label
duration_minutesINTDuration associated with the activity
Tablesusersactivity_logs
Interviewer

Your question is Clean and Transform Disjoint Logs. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.