1.1.2 Reading & writing🔗ℹ

A dataframe is built from named series. gregor datetimes become datetime columns; cast to get a date column.

> (define df
    (~> (dataframe
         (list (series '("Alice Archer" "Ben Brown" "Chloe Cooper" "Daniel Donovan")
                       #:name "name")
               (series (list (datetime 1997 1 10) (datetime 1985 2 15)
                             (datetime 1983 3 22) (datetime 1981 4 30))
                       #:name "birthdate")
               (series '(57.9 72.5 53.6 83.1) #:name "weight")
               (series '(1.56 1.77 1.65 1.75) #:name "height")))
        (with-columns (cast "birthdate" 'date))))
> df

shape: (4, 4)

┌────────────────┬────────────┬────────┬────────┐

│ name           ┆ birthdate  ┆ weight ┆ height │

│ ---            ┆ ---        ┆ ---    ┆ ---    │

│ str            ┆ date       ┆ f64    ┆ f64    │

╞════════════════╪════════════╪════════╪════════╡

│ Alice Archer   ┆ 1997-01-10 ┆ 57.9   ┆ 1.56   │

│ Ben Brown      ┆ 1985-02-15 ┆ 72.5   ┆ 1.77   │

│ Chloe Cooper   ┆ 1983-03-22 ┆ 53.6   ┆ 1.65   │

│ Daniel Donovan ┆ 1981-04-30 ┆ 83.1   ┆ 1.75   │

└────────────────┴────────────┴────────┴────────┘

Round-trip through CSV with write-csv and read-csv; #:try-parse-dates reads the dates back as dates.

> (write-csv df csv-path)
> (read-csv csv-path #:try-parse-dates #t)

shape: (4, 4)

┌────────────────┬────────────┬────────┬────────┐

│ name           ┆ birthdate  ┆ weight ┆ height │

│ ---            ┆ ---        ┆ ---    ┆ ---    │

│ str            ┆ date       ┆ f64    ┆ f64    │

╞════════════════╪════════════╪════════╪════════╡

│ Alice Archer   ┆ 1997-01-10 ┆ 57.9   ┆ 1.56   │

│ Ben Brown      ┆ 1985-02-15 ┆ 72.5   ┆ 1.77   │

│ Chloe Cooper   ┆ 1983-03-22 ┆ 53.6   ┆ 1.65   │

│ Daniel Donovan ┆ 1981-04-30 ┆ 83.1   ┆ 1.75   │

└────────────────┴────────────┴────────┴────────┘

API gap: no date dtype from gregor date values.