Points.fillMatching¶
- Points.fillMatching(fillWith, matchingElements, points=None, *, useLog=None, **kwarguments)¶
Replace given values in each point with other values.
Fill matching values within each point with a specified value based on the values in that point. The
fillWith
value can be a constant or a determined based on unmatched values in the point. The match and fill modules in nimble offer common functions for these operations.- Parameters:
fillWith (value or function) –
value - a value to fill each matching value in each point
function - must be in the format: fillWith(point, matchingElements) or fillWith(point, matchingElements, **kwarguments) and return the transformed point as a list of values. Certain fill methods can be imported from nimble’s fill module.
matchingElements (value, list, or function) –
value - a value to locate within each point
list - values to locate within each point
function - must accept a single value and return True if the value is a match. Certain match types can be imported from nimble’s match module.
query - string in the format ‘OPERATOR VALUE’ representing a function (i.e “< 10”, “== yes”, or “is missing”). See
nimble.match.QueryString
for string requirements.
points (identifier, list of identifiers, None) – Select specific points to apply the fill to. If points is None, the fill will be applied to all points.
useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.
kwarguments – Provide additional parameters to a
fillWith
function.
Examples
Fill a value with another value.
>>> lst = [[1, 1, 1], ... [1, 1, 1], ... [1, 1, 'na'], ... [2, 2, 2], ... ['na', 2, 2]] >>> X = nimble.data(lst) >>> X.points.fillMatching(-1, 'na') >>> X <DataFrame 5pt x 3ft 0 1 2 ┌────────── 0 │ 1 1 1 1 │ 1 1 1 2 │ 1 1 -1 3 │ 2 2 2 4 │ -1 2 2 >
Fill using nimble’s match and fill modules; limit to last point. Note: None is converted to np.nan in nimble.
>>> from nimble import match >>> from nimble import fill >>> lst = [[1, 1, 1], ... [1, 1, 1], ... [1, 1, None], ... [2, 2, 2], ... [None, 2, 2]] >>> X = nimble.data(lst) >>> X.points.fillMatching(fill.mode, match.missing, points=4) >>> X <Matrix 5pt x 3ft 0 1 2 ┌──────────────────── 0 │ 1.000 1.000 1.000 1 │ 1.000 1.000 1.000 2 │ 1.000 1.000 3 │ 2.000 2.000 2.000 4 │ 2.000 2.000 2.000 >