Skip to main content

dftk — DataFrame analysis and manipulation toolkit

dftk is a command-line toolkit for exploratory data analysis on TSV files. Each subcommand reads tabular data, performs one operation, and writes TSV to stdout, making it easy to chain commands in pipelines.

dftk was developed during computational genomics research as a fast, composable alternative to writing one-off pandas scripts. It is designed for analysts who live in the terminal and want a consistent, pipeable toolkit for the full data analysis pipeline — from initial exploration through statistical modelling and publication-quality figures.

No data file handy? Every example below uses dftk dataset to pull in a small, real dataset, so you can copy-paste any of them and run them right now. Run dftk dataset --list to browse everything available (dozens of datasets from seaborn, statsmodels, and pydataset). dftk dataset NAME searches all three sources in that order and returns the first match, so --source is optional — pass it only to disambiguate a name that exists in more than one source, or to restrict the search.

Installation

uv tool install dataframe-toolkit
dftk --help

Or with pip:

pip install dataframe-toolkit

To install the latest main branch directly from GitHub:

uv tool install git+https://github.com/hemingur/dataframe-toolkit.git

To install from a local clone:

git clone https://github.com/hemingur/dataframe-toolkit.git
cd dataframe-toolkit
uv tool install .

Quick example

dftk dataset tips | dftk stat - -c tip total_bill -g day

Chain commands with -o (write to a temp parquet, print its path) and ... (read a parquet path from stdin) instead of piping TSV text directly — faster for large data, and the recommended pattern once a pipeline has more than one step:

dftk dataset tips -o \
  | dftk pivot ... -i day -v tip -f mean -o \
  | dftk print ...

Subcommands

Data transformation

Command Description
eval Add or modify columns: eval expressions, string/path functions, statistical ops
query Filter rows with pandas query expressions or SQL (--sql via DuckDB)
merge Join two tables on key columns (inner/left/right/outer)
concat Concatenate two or more tables row-wise
melt Reshape wide-to-long (pd.melt)
pivot Reshape long-to-wide with per-cell aggregation
func Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N
scale Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals
interp Interpolate values from a reference curve into a table (1-D lookup)
binx Assign bin indices to a column based on explicit or generated edges
transpose Flip rows and columns; original column names land in a new --keycol column
segid Assign a segment ID that increments on each value change in a column

Statistics

Command Description
stat Descriptive statistics (count/mean/std/CI/SEM/skew/kurtosis) with grouping and bootstrap
wstat Weighted descriptive statistics (wmean, wstd, weighted quantile CI)
fit OLS/robust/weighted regression via R-style formulas; tidy table, --summary, --anova
test P-values between column pairs: t-test, Mann-Whitney, Wilcoxon, KS, correlations, bootstrap; groups
corr Pairwise column correlations (Pearson/Spearman/Kendall) with optional BCa bootstrap CI
describe Quick column-level summary (dtype, n, n_unique, n_null, sample values)
info Per-column dtype, null counts, and memory usage; --summary for dataset-level totals
randvar Sample from a distribution and append as a new column (norm, alpha, beta, …)

Plots

All plot commands write a PNG/PDF when -f FILE is given, or display interactively otherwise. They support --groupcol for colour grouping, --subgraphcol for subplot grids, and figure/font presets for publication-quality output.

Command Description
scat Scatter plot; optional OLS/robust fit overlay, bubble size (--sizecol), colour (--colorcol)
line Line plot; optional error bars (--yerr) or CI bands (--yci lo,hi) and fit overlay
hist Histogram or KDE (--kde); normalisation, cumulative mode, mean±σ annotation (--stats)

Utilities

Command Description
dataset Load a curated example dataset from seaborn, statsmodels, or pydataset
sample Random row sampling (with or without replacement, by count or fraction)
split Split a dataframe into one file per group
annotate Read and write provenance metadata (genome, source, …) in parquet files
print Read any dftk input (TSV, stdin, ... parquet pipe) and write TSV
clean Remove leftover temp parquet pipe files from interrupted pipelines
help List all subcommands or show full help for one: dftk help stat

Common patterns

Chaining commands

# z-score sepal_length within species, then fit against petal_length
dftk dataset iris -o \
  | dftk scale ... -c sepal_length -g species -o \
  | dftk fit ... -f "sepal_length_scaled ~ petal_length" -g species

Group summary then plot

dftk dataset tips -o \
  | dftk stat ... -c tip -g day -o \
  | dftk line ... -x day -y mean --yerr sem -f fig.png

Wide-to-long then plot overlaid histograms

dftk dataset iris \
  | dftk melt - -i species -d measurement -v value \
  | dftk hist - -x value -g measurement -k -f dist.png

Interpolation (standard curve lookup)

printf "conc\tfluor\n0\t5\n10\t52\n20\t98\n30\t151\n" > stdcurve.tsv
printf "sample\tfluor\ns1\t60\ns2\t110\n" \
  | dftk interp - --ref stdcurve.tsv -x fluor --refx fluor -v conc -d conc_ng_ul

Bootstrap confidence intervals

Bootstrap mode repeats the full stat computation N times on resampled data and emits one row per resample (tagged with samplenum) — pipe into pivot with percentile aggfuncs (cilo/cihi) to collapse that into an empirical confidence interval:

dftk dataset tips -o \
  | dftk stat ... -c tip -g day --bootstrap 1000 --randomseed 42 -o \
  | dftk pivot ... -i day -v mean -f mean cilo cihi -o \
  | dftk print ...

Input/output

All commands accept:

  • A TSV filename as a positional argument
  • - to read TSV from stdin
  • ... to receive a parquet path from stdin (written by a previous -o command)
  • A .parquet filename to read a named parquet file directly

- vs ... — these are not interchangeable. Use - when the previous command in the pipe wrote plain TSV to stdout (the default). Use ... when the previous command used bare -o (pipe mode), which writes a temp parquet and prints its path to stdout — - would try to parse that path as TSV and fail.

Standard output options (available on all tabular commands):

  • -o / --output — controls where output goes; takes an optional value:
    • -o alone — write a temp parquet to pipe into the next command, printing its path to stdout (auto-deleted once read)
    • -o FILE.parquet — write a named, reusable parquet, printing its path to stdout
    • -o FILE (no .parquet extension) — write TSV to FILE, with no stdout output
    • omit -o entirely — write TSV to stdout (the default)
  • --select col1 col2 … — keep only these columns
  • --drop col1 col2 … — remove these columns
  • --round N — round numeric output
  • --postquery EXPR — filter output rows after processing
  • --meta KEY=VALUE — embed provenance metadata in parquet output (repeatable)

Provenance annotations

Metadata embedded with --meta is stored in the parquet file schema and propagates automatically through the pipe: every subsequent -o write re-embeds it alongside any new --meta values.

# Tag a file at creation
dftk dataset iris -o iris.parquet --meta source=seaborn --meta species_col=species

# Inspect annotations
dftk annotate iris.parquet
# source        seaborn
# species_col   species

# Add or update an annotation in-place
dftk annotate iris.parquet --set step=raw

# Annotations survive piping
dftk eval iris.parquet -f "petal_area = petal_length * petal_width" -o iris2.parquet
dftk annotate iris2.parquet   # source, species_col, and step all still present

Figure options (plot commands)

--size single|double|full|WxH    figure size (single ≈ 3.5", double ≈ 7.2")
--fontsize screen|publication|presentation
-f FILE                          save to file (PNG/PDF/SVG); omit to display
--groupcol COL                   colour-code by this column
--subgraphcol COL                split into subplot grid by this column
--ncols N                        columns in subplot grid (default: auto)
--legend TEXT                    legend label for ungrouped series

Dependencies

  • pandas, numpy, scipy — core data handling and statistics
  • statsmodels — regression (fit, scale --resid, wstat)
  • duckdb — SQL queries (query --sql)
  • matplotlib, seaborn — plots
  • pyarrow — parquet I/O backend

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataframe_toolkit-0.5.1.tar.gz (74.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dataframe_toolkit-0.5.1-py3-none-any.whl (97.8 kB view details)

Uploaded Python 3

File details

Details for the file dataframe_toolkit-0.5.1.tar.gz.

File metadata

  • Download URL: dataframe_toolkit-0.5.1.tar.gz
  • Upload date:
  • Size: 74.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for dataframe_toolkit-0.5.1.tar.gz
Algorithm Hash digest
SHA256 3a7800fbd132d08dc10ea1b6d9ae630edf268508f4c33bb0d1265e9761f92e09
MD5 73ba15b8d932963987dba0562fa43d8f
BLAKE2b-256 da0aca3bb63432dec8d32ecf7a124d2bd21a13f8105dbeded468547e5478ab27

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataframe_toolkit-0.5.1.tar.gz:

Publisher: publish.yaml on hemingur/dataframe-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dataframe_toolkit-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dataframe_toolkit-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49ea337c94fea7829ba84da73a7b8f4fa3cdd9d674ad88f548edbd61cc2cf724
MD5 e2c5cafc17b561a841dee2057e799dc3
BLAKE2b-256 869d883532c5e930a2935660e087361358a5bca72be51f685514b01666641cf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataframe_toolkit-0.5.1-py3-none-any.whl:

Publisher: publish.yaml on hemingur/dataframe-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page