fill.like and fill.shares.
Study(book, fill={...}, draws=n, seed=s) fills each blank value of a
column, or of a set of columns sampled together, in draws 1 to n. Besides
these two, a fill is any function fn(rng, rows) that returns a value for
every row of the table, or a SciPy distribution, such as
scipy.stats.lognorm(0.4, scale=11_000). Only blank values take the fill;
reported values stay as reported.
::
from relativities import Study, fill
study = Study(
book,
fill={
“vehicles.annual_mileage”: fill.like(“garaging_state”),
“drivers.credit_tier”: fill.shares({“good”: 0.6, “fair”: 0.3, “poor”: 0.1}),
},
draws=200,
seed=7,
)
like
by values.
fill.like("garaging_state", "vehicle_year") fills a blank annual
mileage from a vehicle in the same state and year that reports one. When
that group is empty, it matches on fewer columns, dropping the last first,
and then on the whole table. by names columns of the table it fills.
For a set of columns filled together, one donor gives all of them.
shares
fill.shares({"good": 0.6, "fair": 0.3, "poor": 0.1}) fills about 60% of
blanks with "good". The weights are relative, so {"a": 3, "b": 1} is
75% and 25%. For a set of columns filled together, each value is a tuple
with one item per column.