QuestionQ5
VerifiedDeveloping Code for Data Processing using Python and SQLA data engineer is analyzing transactional data in a PySpark DataFrame df that contains customer_id, transaction_timestamp (precise to milliseconds), and amount_spent. The goal is to calculate a cumulative sum of amount_spent for each customer, strictly ordered by transaction_timestamp. The cumulative sum must include every transaction from the earliest timestamp through and including the current row, while preserving temporal order within each customer partition.
Which PySpark code snippet most accurately defines the required window specification and applies the aggregation to produce the correct cumulative expenditure per customer?
Community Discussion