Patsy

1.0.2 · maintenance · verified Sun Mar 29

Patsy is a Python package for describing statistical models and for building design matrices, bringing R-style formulas to Python. The current version is 1.0.2. While no new feature development is planned, it maintains a maintenance cadence to ensure compatibility with current releases in the Python ecosystem.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `patsy.dmatrices` to generate design matrices from a formula string and a dictionary-like data source. It automatically handles categorical variables and adds an intercept term.

import numpy as np
from patsy import dmatrices, demo_data

# Create example data
data = demo_data("a", "b", "x1", "x2", "y")

# Generate design matrices for a linear model
y, X = dmatrices("y ~ x1 + x2 + a", data=data)

print("Dependent variable (y):")
print(y)
print("\nIndependent variables (X):")
print(X)

view raw JSON →