diive.keep_records_where¶
- diive.keep_records_where(data, target, condition_var, lower=None, upper=None, inclusive='both', invert=False, set_to_nan=True, verbose=False)[source]¶
Select records of one variable based on the value of another variable.
Returns the
targetvariable restricted to the records where a second variable (condition_var) falls within[lower, upper]. A non-destructive conditional subselection (the row-on-a-condition analogue ofkeep_vars/times.keep_daterange): the input is left untouched.At least one of
lower/uppermust be given; an unset bound means that side is open (no limit). Withinvert=False(default), records wherecondition_varis NaN are never kept (a missing condition can’t satisfy the range); withinvert=Truethey are kept (a missing condition can’t be in the removed range either).- Parameters:
data (
DataFrame) – DataFrame containing bothtargetandcondition_var.target (
str) – Column to select records from.condition_var (
str) – Column whose value decides which records are kept.lower (
float) – Lower limit forcondition_var;None= open below.upper (
float) – Upper limit forcondition_var;None= open above.inclusive (
str) – Which bounds are inclusive, passed toSeries.between:'both'(default),'neither','left'or'right'.invert (
bool) – If True, keep records wherecondition_varis outside the range instead of inside it (i.e. remove the in-range records).set_to_nan (
bool) – If True (default), keep the full index and set non-matching records to NaN (preserves regular time spacing). If False, drop the non-matching records and return only the matching ones.verbose (
bool) – Print how many records were kept.
- Return type:
- Returns:
A copy of
data[target]restricted to the matching records.- Raises:
ValueError – If a column is missing or both limits are
None.