Features.replace¶
- Features.replace(data, features=None, *, useLog=None, **dataKwds)¶
Replace the data in one or more of the features in this object.
If
features=None, the data must be a nimble data object with matching featureNames, matching featureNames must be specified as adataKwdsargument or the data must replace all features. Otherwise, the shape of thedataobject must align with thefeaturesparameter. Index values infeatureswill take priority over matching featureNames.- Parameters:
data – The object containing the data to use as a replacement. This can be any
sourceaccepted bynimble.data.features (identifier, list, None) – The feature (name or index) or list of features to replace with the provided data.
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.
dataKwds – Any keyword arguments accepted by
nimble.datato use to construct a nimble data object fromdata. These only apply whendatais not already a nimble data object.
See also
Examples
>>> obj = nimble.zeros(3, 3, featureNames=['a', 'b', 'c']) >>> newFt = nimble.ones(3, 1, featureNames=['b']) >>> obj.features.replace(newFt, features='b') >>> obj <Matrix 3pt x 3ft a b c ┌──────── 0 │ 0 1 0 1 │ 0 1 0 2 │ 0 1 0 >
>>> obj = nimble.zeros(3, 4, returnType='Sparse') >>> replacement = [[1, 9], [2, 8], [3, 7]] >>> obj.features.replace(replacement, [1, 2]) >>> obj <Sparse 3pt x 4ft 0 1 2 3 ┌─────────── 0 │ 0 1 9 0 1 │ 0 2 8 0 2 │ 0 3 7 0 >
>>> obj = nimble.zeros(3, 3, featureNames=['a', 'b', 'c'], ... returnType="DataFrame") >>> obj.features.replace(['Y', 'N', 'Y'], featureNames=['b']) >>> obj <DataFrame 3pt x 3ft a b c ┌──────── 0 │ 0 Y 0 1 │ 0 N 0 2 │ 0 Y 0 >
Keywords: change, substitute, alter, transform