Stratified random treatment assignment using pandas. Designed for randomized controlled trials (RCTs) — assign treatments across any number of strata, with equal or unequal probabilities, and let stochatreat handle the misfits.
pip install stochatreat
# or
conda install -c conda-forge stochatreatfrom stochatreat import stochatreat
import numpy as np
import pandas as pd
df = pd.DataFrame({"id": range(1000), "nhood": np.random.randint(1, 6, 1000)})
treats = stochatreat(data=df, stratum_cols="nhood", treats=2, idx_col="id", random_state=42)
df = df.merge(treats, how="left", on="id")For full documentation and examples visit manmartgarc.github.io/stochatreat.
Read the contributing guide.
