The fraud department wants to flag duplicate transactions. Identify records where the same account has multiple charges for the same amount within the exact same minute.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| txn_id | account_id | timestamp | amount |
|---|---|---|---|
| 1 | 101 | 2026-07-01 10:00:15 | 100.0 |
| 2 | 101 | 2026-07-01 10:00:45 | 100.0 |
| 3 | 101 | 2026-07-01 10:05:00 | 100.0 |
| 4 | 102 | 2026-07-01 10:02:10 | 250.0 |
| 5 | 102 | 2026-07-01 10:02:40 | 250.0 |
txn_id,account_id,timestamp,amount 1,101,2026-07-01 10:00:15,100.0 2,101,2026-07-01 10:00:45,100.0 3,101,2026-07-01 10:05:00,100.0 4,102,2026-07-01 10:02:10,250.0 5,102,2026-07-01 10:02:40,250.0
Copy this starter template to write the data transformation logic:
# starter.py - Detect Duplicate Transactions
from pyspark.sql import SparkSession
from pyspark.sql.window import Window
from pyspark.sql.functions import col, row_number, date_format
def detect_duplicates():
spark = SparkSession.builder.appName("DuplicateDetection").getOrCreate()
# TODO: Read dataset.csv, extract minute, apply row_number() over account/amount/minute
pass
if __name__ == "__main__":
detect_duplicates()date_format(col("timestamp"), "yyyy-MM-dd HH:mm").
account_id, amount, and the extracted txn_minute column, sorting by timestamp.
row_number().over() and filter to return only rows where row_num > 1 to pinpoint duplicate charges.