... patsy: introduction


For this video you'll need to install the following dependencies;

python -m pip install jupyterlab pandas scikit-learn patsy matplotlib

You'll also need the dataset, it can be fetched here or downloaded via;

wget https://calmcode.io/datasets/birthdays.csv

The python code in the beginning of this notebook is;

import patsy as ps
import numpy as np
import pandas as pd
import matplotlib.pylab as plt

from sklearn.linear_model import LinearRegression

df = pd.read_csv("birthdays.csv")

def clean_data(dataf):
    return (dataf
            .drop(columns=['Unnamed: 0'])
            .assign(date = lambda d: pd.to_datetime(d['date']))
            .groupby(['date', 'wday', 'month'])
            .agg(n_born=('births', 'sum'))
            .assign(yday = lambda d: d['date'].dt.dayofyear))

df_clean = df.pipe(clean_data)

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider signing up for the newsletter.