Skip to main content

Rolling

Struct Rolling 

Source
pub struct Rolling<'a> { /* private fields */ }
Expand description

Rolling window aggregation over a Series.

Created by Series::rolling(). Provides methods for computing rolling statistics over a sliding window.

Implementations§

Source§

impl Rolling<'_>

Source

pub fn sum(&self) -> Result<Series, FrameError>

Rolling sum.

Source

pub fn mean(&self) -> Result<Series, FrameError>

Rolling mean.

Source

pub fn min(&self) -> Result<Series, FrameError>

Rolling minimum.

Source

pub fn max(&self) -> Result<Series, FrameError>

Rolling maximum.

Source

pub fn std(&self) -> Result<Series, FrameError>

Rolling sample standard deviation (ddof=1).

Examples found in repository?
examples/bench_rolling_var.rs (line 72)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn count(&self) -> Result<Series, FrameError>

Rolling count of non-null values.

pandas count() is special: min_periods checks WINDOW SIZE, not non-null count. This differs from sum/mean/etc. where min_periods checks non-null count. If the window has at least min_periods elements, count returns the number of non-nulls (which can be 0).

Source

pub fn var(&self) -> Result<Series, FrameError>

Rolling sample variance (ddof=1).

Examples found in repository?
examples/bench_rolling_var.rs (line 71)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn median(&self) -> Result<Series, FrameError>

Rolling median.

Source

pub fn first(&self) -> Result<Series, FrameError>

Rolling first non-null value.

Source

pub fn last(&self) -> Result<Series, FrameError>

Rolling last non-null value.

Source

pub fn prod(&self) -> Result<Series, FrameError>

Rolling product.

Examples found in repository?
examples/bench_rolling_var.rs (line 76)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn quantile(&self, q: f64) -> Result<Series, FrameError>

Rolling quantile.

Matches series.rolling(window).quantile(q).

Source

pub fn apply<F>(&self, func: F) -> Result<Series, FrameError>
where F: Fn(&[f64]) -> f64,

Apply a custom function over the rolling window.

Matches series.rolling(window).apply(func).

Source

pub fn corr(&self, other: &Series) -> Result<Series, FrameError>

Rolling pairwise correlation with another Series.

Matches series.rolling(window).corr(other). Computes Pearson correlation over each rolling window.

Source

pub fn cov(&self, other: &Series) -> Result<Series, FrameError>

Rolling pairwise covariance with another Series.

Matches series.rolling(window).cov(other). Computes sample covariance (ddof=1) over each rolling window.

Source

pub fn skew(&self) -> Result<Series, FrameError>

Rolling skewness (bias=False, Fisher’s definition).

Matches pd.Series.rolling(window).skew().

Examples found in repository?
examples/bench_rolling_var.rs (line 73)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn kurt(&self) -> Result<Series, FrameError>

Rolling excess kurtosis (Fisher’s definition, bias=False).

Matches pd.Series.rolling(window).kurt().

Examples found in repository?
examples/bench_rolling_var.rs (line 74)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn kurtosis(&self) -> Result<Series, FrameError>

Alias for kurt() — pandas exposes both spellings on Series.rolling aggregations.

Source

pub fn agg(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>

Aggregate with multiple functions, returning a DataFrame.

Matches series.rolling(window).agg(['sum', 'mean']). Returns a DataFrame with one column per function, same index as the input.

Source

pub fn aggregate(&self, funcs: &[&str]) -> Result<DataFrame, FrameError>

pandas alias for Self::agg.

Matches series.rolling(window).aggregate([...]).

Source

pub fn sem(&self) -> Result<Series, FrameError>

Rolling standard error of the mean.

Matches series.rolling(window).sem().

Examples found in repository?
examples/bench_rolling_var.rs (line 75)
64fn run_api(s: &Series, window: usize, min_periods: Option<usize>, center: bool, a: Agg) -> Series {
65    let r = if center {
66        s.rolling_center(window, min_periods)
67    } else {
68        s.rolling(window, min_periods)
69    };
70    match a {
71        Agg::Var => r.var(),
72        Agg::Std => r.std(),
73        Agg::Skew => r.skew(),
74        Agg::Kurt => r.kurt(),
75        Agg::Sem => r.sem(),
76        Agg::Prod => r.prod(),
77    }
78    .unwrap()
79}
Source

pub fn rank( &self, method: &str, ascending: bool, na_option: &str, ) -> Result<Series, FrameError>

Rank the current observation within each rolling window.

Matches series.rolling(window).rank(). The emitted value is the rank of the row’s own value within its window.

Source

pub fn exclusions(&self) -> Vec<String>

Frozenset-style label set excluded from this rolling window.

Series rolling windows have no excluded columns.

Source

pub fn ndim(&self) -> usize

Number of dimensions of the underlying object. Series rolling is 1D.

Auto Trait Implementations§

§

impl<'a> Freeze for Rolling<'a>

§

impl<'a> RefUnwindSafe for Rolling<'a>

§

impl<'a> Send for Rolling<'a>

§

impl<'a> Sync for Rolling<'a>

§

impl<'a> Unpin for Rolling<'a>

§

impl<'a> UnsafeUnpin for Rolling<'a>

§

impl<'a> UnwindSafe for Rolling<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.