Reference library

Big data & Spark

PySpark jobs, partitioning, batch processing, and large-dataset transform patterns.

3 matches
Big data & Spark easy

How to Implement collect_list in Python

Group rows by a key and collect all corresponding values into a list — a pure-Python mock of Spark's collect_list aggregation.

collect_list aggregation grouping
Python
from collections import defaultdict

def collect_list(rows, key_field, value_field):
    grouped = defaultdict(list)
    for row in rows:
        grouped[row[key_field]].append(row[value_field])
    return dict(grouped)

if __name__ == "__main__":
    data = [
        {"dept": "sales", "emp": "alice"},
        {"dept"…
15 0 Open
Big data & Spark easy

How to Pivot and Group Aggregate in Python

Group records by a key, collect values, and apply an aggregate function (like sum) to build a pivot-style summary dictionary.

pivot group-by aggregation
Python
from collections import defaultdict

def pivot_group_aggregate(records, group_key, value_key, agg_func):
    groups = defaultdict(list)
    for record in records:
        groups[record[group_key]].append(record[value_key])
    return {key: agg_func(values) for key, values in groups.items()}

if __name__ == "__main__":…
13 0 Open
Big data & Spark medium

How to implement a tumbling window aggregation in Python

Build a mock tumbling window aggregator in Python that groups streaming events into fixed time intervals and computes count, sum, and average per window.

tumbling-window streaming aggregation
Python
import time
from collections import deque

class TumblingWindow:
    def __init__(self, duration_seconds):
        self.duration = duration_seconds
        self.buffer = deque()
        self.window_start = None

    def add(self, item):
        current_time = time.time()
        if self.window_start is None:
         …
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Big data & Spark — Python code examples

What you will find here

This page collects big data & spark snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.