Reference library

Big data & Spark

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

3 matches
Big data & Spark easy

How to Shuffle Items by Group in Python

Randomly shuffle items within each group while keeping groups contiguous, using a seed for reproducible results.

random shuffle grouping
Python
import random

def shuffle_sort_groups(items, group_key, seed=None):
    """Randomize order within groups, keeping groups contiguous."""
    rng = random.Random(seed)
    
    groups = {}
    for item in items:
        key = group_key(item)
        groups.setdefault(key, []).append(item)
    
    result = []
    for k…
13 0 Open
Big data & Spark easy

Session window gap mock in Python

Group sorted timestamps into sessions where any gap between consecutive events exceeds a threshold starts a new session.

timestamps sessions windowing
Python
from datetime import datetime, timedelta


def session_windows(timestamps, gap_seconds=300):
    """Group timestamps into sessions where gaps > gap_seconds start new sessions."""
    if not timestamps:
        return []

    # Sort timestamps chronologically to ensure correct windowing
    timestamps = sorted(timestam…
14 0 Open
Big data & Spark easy

Z-Order Optimization in Python

A mock concept demonstrating z-order layout optimization by reassigning z-indices based on areas size.

zorder layout optimization
Python
class ZOrderLayout:
    """
    Minimal mock for z-order layout optimization using a stacking score.
    Elements overlap; higher z_index is drawn on top.
    """
    def __init__(self):
        self.elements = []

    def add_element(self, name, area, z_index):
        self.elements.append({"name": name, "area": area…
12 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.