Calmcode - altair: example

How to make a scatter chart with Altair.

1 2 3 4 5 6 7 8 9

The code from the previous video is shown below.

import pathlib
import pandas as pd
import altair as alt

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

def clean_dataset(dataf):
    return (dataf
            .assign(date = lambda d: pd.to_datetime(d['date']))
            .assign(yday = lambda d: d['date'].dt.dayofyear)
            .groupby(['date', 'wday', 'yday'])
            .agg(births = ('births', 'sum'), month=('month', 'first'))

plot_df = df.pipe(clean_dataset)

First Example of Altair

To turn this dataset into an interactive chart, run the example code below.

  .encode(x='yday', y='births')
  .properties(width=600, height=300)