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
PySpark Transformations
00:00
5 left

PySpark Transformations

MediumPython

Problem

What PySpark transformations have you implemented in your recent projects?

Implement the equivalent transformation pipeline as transform_records(records): filter records with status == "completed" and amount > 0, aggregate total amount and record count by category, then return results sorted by category.

Input records are dictionaries with category, amount, and status. Return dictionaries containing category, total_amount, and count.

Example: [{'category':'A','amount':10,'status':'completed'}] returns [{'category':'A','total_amount':10,'count':1}].

Constraints

  • 0 <= len(records) <= 100000
  • Each record contains category, amount, and status
  • category is a non-empty string
  • amount is an integer or floating-point number
  • status is a string

Function Signature

def transform_records(records):
Interviewer

Your question is PySpark Transformations. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.