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
PySpark Data Cleaning and EDA
00:00
5 left

PySpark Data Cleaning and EDA

MediumSQL · PostgreSQL

Problem

Tell me about how you would clean a dataset and perform descriptive data analysis using PySpark.

For this SQL exercise, write a PostgreSQL query that cleans the transaction records and summarizes valid completed transactions by customer segment. Treat duplicate transaction IDs as one record, keeping the latest ingestion, and exclude invalid amounts or dates.

Output

  1. One row per customer segment, including Unknown when no usable segment exists
  2. Columns: customer_segment, transaction_count, total_amount, average_amount, minimum_amount, maximum_amount
  3. Include only valid completed transactions with positive amounts and valid dates
  4. Order by total_amount descending, then customer_segment ascending

Schema

raw_transactions
ColumnTypeDescription
row_idPKINTUnique physical row identifier
transaction_idVARCHAR(20)Logical transaction identifier, which can be duplicated across ingestions
customer_idVARCHAR(20)Customer identifier from the source transaction data
amount_textVARCHAR(40)Transaction amount stored as raw text
status_textVARCHAR(30)Raw transaction status
transaction_date_textVARCHAR(20)Transaction date stored as raw text
ingested_atTIMESTAMPTimestamp when the source record was ingested
customer_reference
ColumnTypeDescription
customer_idPKVARCHAR(20)Customer identifier
segmentVARCHAR(40)Customer segment, which may be missing
Tablesraw_transactionscustomer_reference
Interviewer

Your question is PySpark Data Cleaning and EDA. 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.