nimble.fill.mean

nimble.fill.mean(vector, match)

Fill matched values with the mean.

The calculation of the mean will ignore any matched values, but all unmatched values must be numeric. If all the values are a match the mean cannot be calculated.

Parameters:
  • vector (nimble point or feature) – A nimble Base object containing one point or feature.

  • match (value or function) –

    • value - The value which should be filled if it occurs in the data.

    • function - Input a value and return True if that value should be filled. Nimble offers common use-case functions in its match module.

Returns:

list – The vector values with the mean replacing the match values.

See also

median, mode, nimble.match

Examples

Match a value.

>>> lst = [1, 'na', 3, 'na', 5]
>>> X = nimble.data(lst)
>>> mean(X, 'na')
<DataFrame 1pt x 5ft
     0    1    2    3    4
   ┌──────────────────────
 0 │ 1  3.000  3  3.000  5
>

Match using a function from nimble’s match module.

>>> from nimble import match
>>> lst = [6, 0, 2, 0, 4]
>>> X = nimble.data(lst)
>>> mean(X, match.zero)
<Matrix 1pt x 5ft
       0      1      2      3      4
   ┌──────────────────────────────────
 0 │ 6.000  4.000  2.000  4.000  4.000
>