1.1.4 Combining dataframes
1.1.4.1 Joining
> (define df2 (dataframe (list (series '("Ben Brown" "Daniel Donovan" "Alice Archer" "Chloe Cooper") #:name "name") (series '(#t #f #f #f) #:name "parent") (series '(1 2 3 4) #:name "siblings")))) > (join df df2 #:on '("name") #:how 'left)
shape: (4, 6)
┌────────────────┬────────────┬────────┬────────┬────────┬──────────┐
│ name ┆ birthdate ┆ weight ┆ height ┆ parent ┆ siblings │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ date ┆ f64 ┆ f64 ┆ bool ┆ i64 │
╞════════════════╪════════════╪════════╪════════╪════════╪══════════╡
│ Alice Archer ┆ 1997-01-10 ┆ 57.9 ┆ 1.56 ┆ false ┆ 3 │
│ Ben Brown ┆ 1985-02-15 ┆ 72.5 ┆ 1.77 ┆ true ┆ 1 │
│ Chloe Cooper ┆ 1983-03-22 ┆ 53.6 ┆ 1.65 ┆ false ┆ 4 │
│ Daniel Donovan ┆ 1981-04-30 ┆ 83.1 ┆ 1.75 ┆ false ┆ 2 │
└────────────────┴────────────┴────────┴────────┴────────┴──────────┘
API gap: #:on takes a list of names, not a bare name.
1.1.4.2 Concatenating
> (define df3 (~> (dataframe (list (series '("Ethan Edwards" "Fiona Foster" "Grace Gibson" "Henry Harris") #:name "name") (series (list (datetime 1977 5 10) (datetime 1975 6 23) (datetime 1973 7 22) (datetime 1971 8 3)) #:name "birthdate") (series '(67.9 72.5 57.6 93.1) #:name "weight") (series '(1.76 1.6 1.66 1.8) #:name "height"))) (with-columns (cast "birthdate" 'date)))) > (vstack df df3)
shape: (8, 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 │
│ Ethan Edwards ┆ 1977-05-10 ┆ 67.9 ┆ 1.76 │
│ Fiona Foster ┆ 1975-06-23 ┆ 72.5 ┆ 1.6 │
│ Grace Gibson ┆ 1973-07-22 ┆ 57.6 ┆ 1.66 │
│ Henry Harris ┆ 1971-08-03 ┆ 93.1 ┆ 1.8 │
└────────────────┴────────────┴────────┴────────┘
API gap: no n-ary concat with a how; vstack is pairwise vertical concatenation.