diff --git a/lessons/05_joins.md b/lessons/05_joins.md index 2421a32..973b61b 100644 --- a/lessons/05_joins.md +++ b/lessons/05_joins.md @@ -188,6 +188,14 @@ result.select("PatID", "RxDate", "Rx").unique() df.height # same as len(df), but clearer intent ``` +**`pl.read_parquet(path)`:** Load a Parquet file into a DataFrame. You'll use this at the start of most exercises to load the tables you'll join. + +```python +df_demographic = pl.read_parquet("data/demographic.parquet") +df_enrollment = pl.read_parquet("data/enrollment.parquet") +df_dispensing = pl.read_parquet("data/dispensing.parquet") +``` + > **SAS reflex check:** IN= flags become how=. MERGE + IF a AND b ↔ how="inner"; IF a ↔ how="left"; IF a AND NOT b ↔ how="anti". But MERGE BY does a one-to-one walk within BY groups — join() always produces the full match combination, so expect row multiplication where SAS would have quietly aligned rows. ## Worked example diff --git a/solutions/ex06_write_and_partition.py b/solutions/ex06_write_and_partition.py index 1ea0cca..086b0b7 100644 --- a/solutions/ex06_write_and_partition.py +++ b/solutions/ex06_write_and_partition.py @@ -30,8 +30,8 @@ def main() -> None: # TODO 1: Read data/dispensing.parquet into a DataFrame called df. df = pl.read_parquet(DISPENSING_PATH) - # TODO 2: Write the 2021 dispensings to - # data/output/dispensing_2021.parquet (create OUTPUT_DIR first). + # TODO 2: Write the 2021 dispensings to data/output/dispensing_2021.parquet. + # Create OUTPUT_DIR first if it doesn't exist. OUTPUT_DIR.mkdir(exist_ok=True) df_2021 = df.filter(pl.col("RxDate").dt.year() == 2021) df_2021.write_parquet(str(OUTPUT_DIR / "dispensing_2021.parquet"))