Features.fillMatching¶
- Features.fillMatching(fillWith, matchingElements, features=None, *, useLog=None, **kwarguments)¶
Replace given values in each feature with other values.
Fill matching values within each feature with a specified value based on the values in that feature. The
fill
value can be a constant or a determined based on unmatched values in the feature. 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 feature
function - must be in the format: fillWith(feature, matchingElements) or fillWith(feature, matchingElements, **kwarguments) and return the transformed feature 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 feature
list - values to locate within each feature
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.
features (identifier or list of identifiers) – Select specific features to apply fill to. If features is None, the fill will be applied to all features.
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.features.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 first feature. 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.features.fillMatching(fill.mean, match.missing, features=0) >>> 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 │ 1.250 2.000 2.000 >