utilities.trim()
Trim a numeric vector by removing extreme observations.
Usage
utilities.trim(
x,
cut,
)Drops values below the lower ‘cut’ quantile and above the upper ‘1 - cut’ quantile. The returned vector is therefore shorter than the input.
Parameters
x: numpy.ndarray or polars.Series-
A numeric vector to trim.
cut: float- Proportion of observations removed at each tail. For example, ‘cut=0.05’ removes the lowest and highest five percent. Must lie in ‘[0, 0.5]’.
Returns
numpy.ndarray- Vector with the extreme observations removed.
Examples
import numpy as np
from tidyfinance import trim
rng = np.random.default_rng(123)
data = rng.standard_normal(100)
trimmed = trim(data, 0.05)