13 Missing values
Occasionally, a data-set will have a literal missing value. While reading data into a data-frame, this can be specified with df-read/csv’s #:na argument; but usually, this value ends up being #f.
These operations are designed to handle missing values, either by replacing them or dropping them.
procedure
(replace-na df column-name replace-with ...)
→ (or/c data-frame? grouped-data-frame?) df : (or/c data-frame? grouped-data-frame?) column-name : string? replace-with : any/c
> (~> has-some-na (replace-na "col-a" 999) show)
data-frame: 3 rows x 2 columns
┌─────┬─────┐
│col-b│col-a│
├─────┼─────┤
│#f │1 │
├─────┼─────┤
│2 │999 │
├─────┼─────┤
│4 │3 │
└─────┴─────┘
> (~> has-some-na (replace-na "col-a" 999 "col-b" 333) show)
data-frame: 3 rows x 2 columns
┌─────┬─────┐
│col-a│col-b│
├─────┼─────┤
│1 │333 │
├─────┼─────┤
│999 │2 │
├─────┼─────┤
│3 │4 │
└─────┴─────┘
syntax
(drop-na df slice-spec)
df : (or/c data-frame? grouped-data-frame?)
The evaluation of slice-spec determines what columns to remove NA values from. For documentation on this language, see Slicing.