Skip to main content

csv-stats

Python package for rapid hypothesis testing on CSV files with data in long table format, which are common in the life sciences. Test results are saved to PDF as a rendered JSON string, or can be returned as a Python dictionary.

Installation

pip install "csv-stats[full]"   # hypothesis tests + PDF reports
pip install csv-stats           # descriptive statistics only (numpy, pandas, scipy)

Descriptive statistics

csvstats.descriptive is the one definition of every descriptive formula: NaN skipped (counted in n_missing), SD with n - 1, linear quartiles, and a t-based 95% CI of the mean. Fewer than two values give NaN, not 0.

from csvstats.descriptive import summarize, ci_interval, ci_half_width

summarize([4.1, 5.0, 6.2, None])   # n=3, n_missing=1, mean, sd, sem, ci_low, ci_high, median, q1, q3, iqr, skewness, kurtosis, ...
ci_interval([4.1, 5.0, 6.2])       # (low, high); also a seaborn errorbar= callable
ci_half_width(sd=1.2, n=5)         # t(0.975, 4) * 1.2 / sqrt(5)

Linear mixed models (0.4.0)

csvstats.lmm uses every observation: a subject missing some within-subject levels is kept, not dropped (a repeated-measures ANOVA or paired t-test would have to drop it). Random intercept per subject, REML, sum-to-zero coding. Tests use Satterthwaite degrees of freedom, as R's lmerTest does: t(df) per coefficient, a type-III F(q, ddf) per term, and t(df) per pairwise contrast. The pairwise contrasts come from the full model (emmeans-style). Everything is checked against lme4 / lmerTest / emmeans on 75 reference datasets (tests/reference). If a df cannot be computed, the Wald test is reported, labelled df_method: "wald".

from csvstats.lmm import lmm, lmm_pairwise
from csvstats.core import assumption_checks

lmm(df, "step_length", within=["session", "speed"], subject="subject")       # one F(q, ddf) per term
lmm_pairwise(df, "step_length", within=["session", "speed"], subject="subject", factor="session",
             levels={"session": ["post", "pre"]})   # post − pre within each speed, t(df)
assumption_checks(df, "step_length", within=["session"], subject="subject")  # Shapiro–Wilk on residuals (+ Levene)

Examples

All code examples below use the following constants:

DATA_PATH = "path/to/data.csv" # Path to your CSV file
DATA_COLUMN = 'values' # The column to run the hypothesis tests on
GROUP_COLUMN = 'groups' # Grouping variable (i.e. statistical factor)
REPEATED_MEASURES_COLUMN = 'subject_id' # Column indicating repeated measures (e.g. subject IDs)

ANOVA

One way ANOVA is currently supported. They include tests of homogeneity of variance and normality of residuals. Repeated measures ANOVA is also supported, including tests of sphericity.

NOTE: Two- and three-way ANOVA support is planned, but not yet implemented.

from csv_stats.anova import anova1way

# One way ANOVA, independent samples
result_anova1way = anova1way(DATA_PATH, 
                            GROUP_COLUMN, 
                            DATA_COLUMN,                            
                            filename = "anova1way_results.pdf", # Default save name. Enter `None` to not save.
                            render_plot = False # For speed, by default no plots are generated
                        )

# One way ANOVA, repeated measures
result_anova1way_rm = anova1way(DATA_PATH, 
                            GROUP_COLUMN, 
                            DATA_COLUMN,                             
                            repeated_measures_column = REPEATED_MEASURES_COLUMN,
                            filename = "anova1way_results.pdf", # Default save name. Enter `None` to not save.     
                            render_plot = False # For speed, by default no plots are generated                       
                        )

t-test

Both independent samples (one and two samples) and paired samples t-tests are supported. They include tests of homogeneity of variance and normality of residuals.

from csv_stats.ttest import ttest_ind, ttest_dep

# Independent samples t-test 
# Two sample when the GROUP_COLUMN has two groups
# One smaple when the GROUP_COLUMN has one group
result_ttest_ind = ttest_ind(DATA_PATH, 
                            GROUP_COLUMN, 
                            DATA_COLUMN,
                            popmean = 0, # Test against a population mean of 0 (default)
                            filename = "ttest_ind_results.pdf", # Default save name. Enter `None` to not save.
                            render_plot = False # For speed, by default no plots are generated
                        )

# Paired samples t-test
result_ttest_rel = ttest_dep(DATA_PATH, 
                            GROUP_COLUMN, 
                            DATA_COLUMN, 
                            repeated_measures_column = REPEATED_MEASURES_COLUMN,
                            filename = "ttest_dep_results.pdf", # Default save name. Enter `None` to not save.
                            render_plot = False # For speed, by default no plots are generated
                        )

Multiple Data Columns

If you have multiple columns of data that you want to run the same test on, you can specify the data_column argument as "_". This will automatically loop over all columns. Note that to save these results to a file, the filename should be an f-string containing f"{data_column}". The test function will replace data_column with the column name in the file name.

Metadata

Release files for csv-stats 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csv-stats 0.4.0
File Size Uploaded Provenance Actions
csv_stats-0.4.0.tar.gz 181.7 kB Without provenance Details for csv_stats-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for csv-stats 0.4.0
File Interpreter ABI Platform Actions
csv_stats-0.4.0-py3-none-any.whl Python 3 none any Details for csv_stats-0.4.0-py3-none-any.whl

Total release size: 226.3 kB

Release files / csv_stats-0.4.0.tar.gz

Download URL csv_stats-0.4.0.tar.gz
Size 181.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ac7c0b3d44404e1d9850cd3571ccf03282085755d6735c0db522be29a636486c
BLAKE2b-256 checksum
How to use checksums
ec2ed567380176ded85c52ac765780baf203e46f628cbd5d6cbd338ed7882c33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.11

Release files / csv_stats-0.4.0-py3-none-any.whl

Download URL csv_stats-0.4.0-py3-none-any.whl
Size 44.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
defbe8daa5985db2108b4da686af8ceb7f256666e11b0b529fad09182f067776
BLAKE2b-256 checksum
How to use checksums
1d97f5213dbe7078a646ce7dfdeca31d7435cb7e1d7d8cdad118c4beff0f374a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.11

Security for csv-stats 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page