Threaded Parquet Describe Features
Overview
When time-series data is stored as one parquet file per subject (common in wearable/sensor competitions), sequential loading is slow. Use ThreadPoolExecutor to read all files in parallel, compute df.describe() per subject, and flatten the 8-stat-per-column summary into a single feature row. Converts variable-length time-series into fixed-width tabular features in seconds.
Quick Start
import os
import pandas as pd
from concurrent.futures import ThreadPoolExecutor
def process_subject(subject_dir, base_dir):
path = os.path.join(base_dir, subject_dir, 'part-0.parquet')
df = pd.read_parquet(path)
df = df.drop(columns=['step'], errors='ignore')
stats = df.describe().values.reshape(-1)
sid = subject_dir.split('=')[-1]
return stats, sid
def load_timeseries_features(base_dir):
subjects = os.listdir(base_dir)
with ThreadPoolExecutor() as pool:
results = list(pool.map(
lambda s: process_subject(s, base_dir), subjects))
stats, ids = zip(*results)
n_feats = len(stats[0])
df = pd.DataFrame(list(stats),
columns=[f'ts_stat_{i}' for i in range(n_feats)])
df['id'] = ids
return df
ts_features = load_timeseries_features('data/series_train.parquet/')
train = train.merge(ts_features, on='id', how='left')
Workflow
- List all subject directories under the parquet base path
ThreadPoolExecutor.map()reads each parquet and computesdescribe()- Flatten the 8-row x N-column describe output into a 1D vector per subject
- Assemble into a DataFrame and merge with main table on subject ID
Key Decisions
- ThreadPoolExecutor over ProcessPool: parquet reads are I/O-bound, thread pool avoids pickling overhead
- describe() gives 8 stats: count, mean, std, min, 25%, 50%, 75%, max — good baseline coverage
- Drop
stepcolumn: monotonic index adds no information - Naming: generic
ts_stat_icolumns; map back via(stat_idx, col_name)if interpretability needed