Pandas移动平均平滑数据

import numpy as np
import pandas as pd

df = pd.DataFrame()
df["data"] = np.random.rand(30) # 创建数据
print(df)
# 数据也可以是series格式

# 简单移动平均
simp_moving_avg = df["data"].rolling(window=3, center=True, min_periods=1).mean()
window表示平均窗口数据量多少;

center为True,表示第一个数据为原数列的第一个和第二个数据平均,第二个数据为原数列的第一个到第三个平均,以此类推,最后后一个数据为原数列最后一个数据和倒数第二个数据平均;

center如果为False,表示第一个数据不做处理,第二个数据为原数列第一和第二个数据平均,第三个数据为原数列前三个数据平均,以此类推。

以下为系统帮助内容

Help on Rolling in module pandas.core.window.rolling object:

class Rolling(RollingAndExpandingMixin)
 |  Rolling(obj: 'NDFrame', window=None, min_periods: 'int | None' = None, center: 'bool' = False, win_type: 'str | None' = None, axis: 'Axis' = 0, on: 'str | Index | None' = None, closed: 'str | None' = None, method: 'str' = 'single', *, selection=None)
 |  
 |  Provide rolling window calculations.
 |  
 |  Parameters
 |  ----------
 |  window : int, offset, or BaseIndexer subclass
 |      Size of the moving window.
 |  
 |      If an integer, the fixed number of observations used for
 |      each window.
 |  
 |      If an offset, the time period of each window. Each
 |      window will be a variable sized based on the observations included in
 |      the time-period. This is only valid for datetimelike indexes.
 |      To learn more about the offsets & frequency strings, please see `this link
 |      <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.
 |  
 |      If a BaseIndexer subclass, the window boundaries
 |      based on the defined ``get_window_bounds`` method. Additional rolling
 |      keyword arguments, namely ``min_periods``, ``center``, and
 |      ``closed`` will be passed to ``get_window_bounds``.
 |  
 |  min_periods : int, default None
 |      Minimum number of observations in window required to have a value;
 |      otherwise, result is ``np.nan``.
 |  
 |      For a window that is specified by an offset, ``min_periods`` will default to 1.
 |  
 |      For a window that is specified by an integer, ``min_periods`` will default
 |      to the size of the window.
 |  
 |  center : bool, default False
 |      If False, set the window labels as the right edge of the window index.
 |  
 |      If True, set the window labels as the center of the window index.
 |  
 |  win_type : str, default None
 |      If ``None``, all points are evenly weighted.
 |  
 |      If a string, it must be a valid `scipy.signal window function
 |      <https://docs.scipy.org/doc/scipy/reference/signal.windows.html#module-scipy.signal.windows>`__.
 |  
 |      Certain Scipy window types require additional parameters to be passed
 |      in the aggregation function. The additional parameters must match
 |      the keywords specified in the Scipy window type method signature.
 |  
 |  on : str, optional
 |      For a DataFrame, a column label or Index level on which
 |      to calculate the rolling window, rather than the DataFrame's index.
 |  
 |      Provided integer column is ignored and excluded from result since
 |      an integer index is not used to calculate the rolling window.
 |  
 |  axis : int or str, default 0
 |      If ``0`` or ``'index'``, roll across the rows.
 |  
 |      If ``1`` or ``'columns'``, roll across the columns.
 |  
 |  closed : str, default None
 |      If ``'right'``, the first point in the window is excluded from calculations.
 |  
 |      If ``'left'``, the last point in the window is excluded from calculations.
 |  
 |      If ``'both'``, the no points in the window are excluded from calculations.
 |  
 |      If ``'neither'``, the first and last points in the window are excluded
 |      from calculations.
 |  
 |      Default ``None`` (``'right'``).
 |  
 |      .. versionchanged:: 1.2.0
 |  
 |          The closed parameter with fixed windows is now supported.
 |  
 |  method : str {'single', 'table'}, default 'single'
 |  
 |      .. versionadded:: 1.3.0
 |  
 |      Execute the rolling operation per single column or row (``'single'``)
 |      or over the entire object (``'table'``).
 |  
 |      This argument is only implemented when specifying ``engine='numba'``
 |      in the method call.
 |  
 |  Returns
 |  -------
 |  ``Window`` subclass if a ``win_type`` is passed
 |  
 |  ``Rolling`` subclass if ``win_type`` is not passed
 |  
 |  See Also
 |  --------
 |  expanding : Provides expanding transformations.
 |  ewm : Provides exponential weighted functions.
 |  
 |  Notes
 |  -----
 |  See :ref:`Windowing Operations <window.generic>` for further usage details
 |  and examples.
 |  
 |  Examples
 |  --------
 |  >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
 |  >>> df
 |       B
 |  0  0.0
 |  1  1.0
 |  2  2.0
 |  3  NaN
 |  4  4.0
 |  
 |  **window**
 |  
 |  Rolling sum with a window length of 2 observations.
 |  
 |  >>> df.rolling(2).sum()
 |       B
 |  0  NaN
 |  1  1.0
 |  2  3.0
 |  3  NaN
 |  4  NaN
 |  
 |  Rolling sum with a window span of 2 seconds.
 |  
 |  >>> df_time = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]},
 |  ...                        index = [pd.Timestamp('20130101 09:00:00'),
 |  ...                                 pd.Timestamp('20130101 09:00:02'),
 |  ...                                 pd.Timestamp('20130101 09:00:03'),
 |  ...                                 pd.Timestamp('20130101 09:00:05'),
 |  ...                                 pd.Timestamp('20130101 09:00:06')])
 |  
 |  >>> df_time
 |                         B
 |  2013-01-01 09:00:00  0.0
 |  2013-01-01 09:00:02  1.0
 |  2013-01-01 09:00:03  2.0
 |  2013-01-01 09:00:05  NaN
 |  2013-01-01 09:00:06  4.0
 |  
 |  >>> df_time.rolling('2s').sum()
 |                         B
 |  2013-01-01 09:00:00  0.0
 |  2013-01-01 09:00:02  1.0
 |  2013-01-01 09:00:03  3.0
 |  2013-01-01 09:00:05  NaN
 |  2013-01-01 09:00:06  4.0
 |  
 |  Rolling sum with forward looking windows with 2 observations.
 |  
 |  >>> indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=2)
 |  >>> df.rolling(window=indexer, min_periods=1).sum()
 |       B
 |  0  1.0
 |  1  3.0
 |  2  2.0
 |  3  4.0
 |  4  4.0
 |  
 |  **min_periods**
 |  
 |  Rolling sum with a window length of 2 observations, but only needs a minimum of 1
 |  observation to calculate a value.
 |  
 |  >>> df.rolling(2, min_periods=1).sum()
 |       B
 |  0  0.0
 |  1  1.0
 |  2  3.0
 |  3  2.0
 |  4  4.0
 |  
 |  **center**
 |  
 |  Rolling sum with the result assigned to the center of the window index.
 |  
 |  >>> df.rolling(3, min_periods=1, center=True).sum()
 |       B
 |  0  1.0
 |  1  3.0
 |  2  3.0
 |  3  6.0
 |  4  4.0
 |  
 |  >>> df.rolling(3, min_periods=1, center=False).sum()
 |       B
 |  0  0.0
 |  1  1.0
 |  2  3.0
 |  3  3.0
 |  4  6.0
 |  
 |  **win_type**
 |  
 |  Rolling sum with a window length of 2, using the Scipy ``'gaussian'``
 |  window type. ``std`` is required in the aggregation function.
 |  
 |  >>> df.rolling(2, win_type='gaussian').sum(std=3)
 |            B
 |  0       NaN
 |  1  0.986207
 |  2  2.958621
 |  3       NaN
 |  4       NaN
 |  
 |  Method resolution order:
 |      Rolling
 |      RollingAndExpandingMixin
 |      BaseWindow
 |      pandas.core.base.SelectionMixin
 |      typing.Generic
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  agg = aggregate(self, func, *args, **kwargs)
 |  
 |  aggregate(self, func, *args, **kwargs)
 |      Aggregate using one or more operations over the specified axis.
 |      
 |      Parameters
 |      ----------
 |      func : function, str, list or dict
 |          Function to use for aggregating the data. If a function, must either
 |          work when passed a Series/Dataframe or when passed to Series/Dataframe.apply.
 |      
 |          Accepted combinations are:
 |      
 |          - function
 |          - string function name
 |          - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
 |          - dict of axis labels -> functions, function names or list of such.
 |      
 |      *args
 |          Positional arguments to pass to `func`.
 |      **kwargs
 |          Keyword arguments to pass to `func`.
 |      
 |      Returns
 |      -------
 |      scalar, Series or DataFrame
 |      
 |          The return can be:
 |      
 |          * scalar : when Series.agg is called with single function
 |          * Series : when DataFrame.agg is called with a single function
 |          * DataFrame : when DataFrame.agg is called with several functions
 |      
 |          Return scalar, Series or DataFrame.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling object with Series data.
 |      pandas.DataFrame.rolling : Calling object with DataFrame data.
 |      
 |      Notes
 |      -----
 |      `agg` is an alias for `aggregate`. Use the alias.
 |      
 |      Functions that mutate the passed object can produce unexpected
 |      behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
 |      for more details.
 |      
 |      A passed user-defined-function will be passed a Series for evaluation.
 |      
 |      Examples
 |      --------
 |      >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
 |      >>> df
 |         A  B  C
 |      0  1  4  7
 |      1  2  5  8
 |      2  3  6  9
 |      
 |      >>> df.rolling(2).sum()
 |           A     B     C
 |      0  NaN   NaN   NaN
 |      1  3.0   9.0  15.0
 |      2  5.0  11.0  17.0
 |      
 |      >>> df.rolling(2).agg({"A": "sum", "B": "min"})
 |           A    B
 |      0  NaN  NaN
 |      1  3.0  4.0
 |      2  5.0  5.0
 |  
 |  apply(self, func: 'Callable[..., Any]', raw: 'bool' = False, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, args: 'tuple[Any, ...] | None' = None, kwargs: 'dict[str, Any] | None' = None)
 |      Calculate the rolling custom aggregation function.
 |      
 |      Parameters
 |      ----------
 |      func : function
 |          Must produce a single value from an ndarray input if ``raw=True``
 |          or a single value from a Series if ``raw=False``. Can also accept a
 |          Numba JIT function with ``engine='numba'`` specified.
 |      
 |          .. versionchanged:: 1.0.0
 |      
 |      raw : bool, default False
 |          * ``False`` : passes each row or column as a Series to the
 |            function.
 |          * ``True`` : the passed function will receive ndarray
 |            objects instead.
 |            If you are just applying a NumPy reduction function this will
 |            achieve much better performance.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs rolling apply through C-extensions from cython.
 |          * ``'numba'`` : Runs rolling apply through JIT compiled code from numba.
 |            Only available when ``raw`` is set to ``True``.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.0.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}`` and will be
 |            applied to both the ``func`` and the ``apply`` rolling aggregation.
 |      
 |            .. versionadded:: 1.0.0
 |      
 |      args : tuple, default None
 |          Positional arguments to be passed into func.
 |      
 |      kwargs : dict, default None
 |          Keyword arguments to be passed into func.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.apply : Aggregating apply for Series.
 |      pandas.DataFrame.apply : Aggregating apply for DataFrame.
 |  
 |  corr(self, other: 'DataFrame | Series | None' = None, pairwise: 'bool | None' = None, ddof: 'int' = 1, **kwargs)
 |      Calculate the rolling correlation.
 |      
 |      Parameters
 |      ----------
 |      other : Series or DataFrame, optional
 |          If not supplied then will default to self and produce pairwise
 |          output.
 |      pairwise : bool, default None
 |          If False then only matching columns between self and other will be
 |          used and the output will be a DataFrame.
 |          If True then all pairwise combinations will be calculated and the
 |          output will be a MultiIndexed DataFrame in the case of DataFrame
 |          inputs. In the case of missing elements, only complete pairwise
 |          observations will be used.
 |      ddof : int, default 1
 |          Delta Degrees of Freedom.  The divisor used in calculations
 |          is ``N - ddof``, where ``N`` represents the number of elements.
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      cov : Similar method to calculate covariance.
 |      numpy.corrcoef : NumPy Pearson's correlation calculation.
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.corr : Aggregating corr for Series.
 |      pandas.DataFrame.corr : Aggregating corr for DataFrame.
 |      
 |      Notes
 |      -----
 |      This function uses Pearson's definition of correlation
 |      (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient).
 |      
 |      When `other` is not specified, the output will be self correlation (e.g.
 |      all 1's), except for :class:`~pandas.DataFrame` inputs with `pairwise`
 |      set to `True`.
 |      
 |      Function will return ``NaN`` for correlations of equal valued sequences;
 |      this is the result of a 0/0 division error.
 |      
 |      When `pairwise` is set to `False`, only matching columns between `self` and
 |      `other` will be used.
 |      
 |      When `pairwise` is set to `True`, the output will be a MultiIndex DataFrame
 |      with the original index on the first level, and the `other` DataFrame
 |      columns on the second level.
 |      
 |      In the case of missing elements, only complete pairwise observations
 |      will be used.
 |      
 |      Examples
 |      --------
 |      The below example shows a rolling calculation with a window size of
 |      four matching the equivalent function call using :meth:`numpy.corrcoef`.
 |      
 |      >>> v1 = [3, 3, 3, 5, 8]
 |      >>> v2 = [3, 4, 4, 4, 8]
 |      >>> # numpy returns a 2X2 array, the correlation coefficient
 |      >>> # is the number at entry [0][1]
 |      >>> print(f"{np.corrcoef(v1[:-1], v2[:-1])[0][1]:.6f}")
 |      0.333333
 |      >>> print(f"{np.corrcoef(v1[1:], v2[1:])[0][1]:.6f}")
 |      0.916949
 |      >>> s1 = pd.Series(v1)
 |      >>> s2 = pd.Series(v2)
 |      >>> s1.rolling(4).corr(s2)
 |      0         NaN
 |      1         NaN
 |      2         NaN
 |      3    0.333333
 |      4    0.916949
 |      dtype: float64
 |      
 |      The below example shows a similar rolling calculation on a
 |      DataFrame using the pairwise option.
 |      
 |      >>> matrix = np.array([[51., 35.], [49., 30.], [47., 32.],        [46., 31.], [50., 36.]])
 |      >>> print(np.corrcoef(matrix[:-1,0], matrix[:-1,1]).round(7))
 |      [[1.         0.6263001]
 |       [0.6263001  1.       ]]
 |      >>> print(np.corrcoef(matrix[1:,0], matrix[1:,1]).round(7))
 |      [[1.         0.5553681]
 |       [0.5553681  1.        ]]
 |      >>> df = pd.DataFrame(matrix, columns=['X','Y'])
 |      >>> df
 |            X     Y
 |      0  51.0  35.0
 |      1  49.0  30.0
 |      2  47.0  32.0
 |      3  46.0  31.0
 |      4  50.0  36.0
 |      >>> df.rolling(4).corr(pairwise=True)
 |                  X         Y
 |      0 X       NaN       NaN
 |        Y       NaN       NaN
 |      1 X       NaN       NaN
 |        Y       NaN       NaN
 |      2 X       NaN       NaN
 |        Y       NaN       NaN
 |      3 X  1.000000  0.626300
 |        Y  0.626300  1.000000
 |      4 X  1.000000  0.555368
 |        Y  0.555368  1.000000
 |  
 |  count(self)
 |      Calculate the rolling count of non NaN observations.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.count : Aggregating count for Series.
 |      pandas.DataFrame.count : Aggregating count for DataFrame.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([2, 3, np.nan, 10])
 |      >>> s.rolling(2).count()
 |      0    1.0
 |      1    2.0
 |      2    1.0
 |      3    1.0
 |      dtype: float64
 |      >>> s.rolling(3).count()
 |      0    1.0
 |      1    2.0
 |      2    2.0
 |      3    2.0
 |      dtype: float64
 |      >>> s.rolling(4).count()
 |      0    1.0
 |      1    2.0
 |      2    2.0
 |      3    3.0
 |      dtype: float64
 |  
 |  cov(self, other: 'DataFrame | Series | None' = None, pairwise: 'bool | None' = None, ddof: 'int' = 1, **kwargs)
 |      Calculate the rolling sample covariance.
 |      
 |      Parameters
 |      ----------
 |      other : Series or DataFrame, optional
 |          If not supplied then will default to self and produce pairwise
 |          output.
 |      pairwise : bool, default None
 |          If False then only matching columns between self and other will be
 |          used and the output will be a DataFrame.
 |          If True then all pairwise combinations will be calculated and the
 |          output will be a MultiIndexed DataFrame in the case of DataFrame
 |          inputs. In the case of missing elements, only complete pairwise
 |          observations will be used.
 |      ddof : int, default 1
 |          Delta Degrees of Freedom.  The divisor used in calculations
 |          is ``N - ddof``, where ``N`` represents the number of elements.
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.cov : Aggregating cov for Series.
 |      pandas.DataFrame.cov : Aggregating cov for DataFrame.
 |  
 |  kurt(self, **kwargs)
 |      Calculate the rolling Fisher's definition of kurtosis without bias.
 |      
 |      Parameters
 |      ----------
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      scipy.stats.kurtosis : Reference SciPy method.
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.kurt : Aggregating kurt for Series.
 |      pandas.DataFrame.kurt : Aggregating kurt for DataFrame.
 |      
 |      Notes
 |      -----
 |      A minimum of four periods is required for the calculation.
 |      
 |      Examples
 |      --------
 |      The example below will show a rolling calculation with a window size of
 |      four matching the equivalent function call using `scipy.stats`.
 |      
 |      >>> arr = [1, 2, 3, 4, 999]
 |      >>> import scipy.stats
 |      >>> print(f"{scipy.stats.kurtosis(arr[:-1], bias=False):.6f}")
 |      -1.200000
 |      >>> print(f"{scipy.stats.kurtosis(arr[1:], bias=False):.6f}")
 |      3.999946
 |      >>> s = pd.Series(arr)
 |      >>> s.rolling(4).kurt()
 |      0         NaN
 |      1         NaN
 |      2         NaN
 |      3   -1.200000
 |      4    3.999946
 |      dtype: float64
 |  
 |  max(self, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling maximum.
 |      
 |      Parameters
 |      ----------
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.max : Aggregating max for Series.
 |      pandas.DataFrame.max : Aggregating max for DataFrame.
 |      
 |      Notes
 |      -----
 |      See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for extended documentation and performance considerations for the Numba engine.
 |  
 |  mean(self, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling mean.
 |      
 |      Parameters
 |      ----------
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.mean : Aggregating mean for Series.
 |      pandas.DataFrame.mean : Aggregating mean for DataFrame.
 |      
 |      Notes
 |      -----
 |      See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for extended documentation and performance considerations for the Numba engine.
 |      
 |      Examples
 |      --------
 |      The below examples will show rolling mean calculations with window sizes of
 |      two and three, respectively.
 |      
 |      >>> s = pd.Series([1, 2, 3, 4])
 |      >>> s.rolling(2).mean()
 |      0    NaN
 |      1    1.5
 |      2    2.5
 |      3    3.5
 |      dtype: float64
 |      
 |      >>> s.rolling(3).mean()
 |      0    NaN
 |      1    NaN
 |      2    2.0
 |      3    3.0
 |      dtype: float64
 |  
 |  median(self, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling median.
 |      
 |      Parameters
 |      ----------
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.median : Aggregating median for Series.
 |      pandas.DataFrame.median : Aggregating median for DataFrame.
 |      
 |      Notes
 |      -----
 |      See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for extended documentation and performance considerations for the Numba engine.
 |      
 |      Examples
 |      --------
 |      Compute the rolling median of a series with a window size of 3.
 |      
 |      >>> s = pd.Series([0, 1, 2, 3, 4])
 |      >>> s.rolling(3).median()
 |      0    NaN
 |      1    NaN
 |      2    1.0
 |      3    2.0
 |      4    3.0
 |      dtype: float64
 |  
 |  min(self, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling minimum.
 |      
 |      Parameters
 |      ----------
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.min : Aggregating min for Series.
 |      pandas.DataFrame.min : Aggregating min for DataFrame.
 |      
 |      Notes
 |      -----
 |      See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for extended documentation and performance considerations for the Numba engine.
 |      
 |      Examples
 |      --------
 |      Performing a rolling minimum with a window size of 3.
 |      
 |      >>> s = pd.Series([4, 3, 5, 2, 6])
 |      >>> s.rolling(3).min()
 |      0    NaN
 |      1    NaN
 |      2    3.0
 |      3    2.0
 |      4    2.0
 |      dtype: float64
 |  
 |  quantile(self, quantile: 'float', interpolation: 'str' = 'linear', **kwargs)
 |      Calculate the rolling quantile.
 |      
 |      Parameters
 |      ----------
 |      quantile : float
 |          Quantile to compute. 0 <= quantile <= 1.
 |      interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
 |          This optional parameter specifies the interpolation method to use,
 |          when the desired quantile lies between two data points `i` and `j`:
 |      
 |              * linear: `i + (j - i) * fraction`, where `fraction` is the
 |                fractional part of the index surrounded by `i` and `j`.
 |              * lower: `i`.
 |              * higher: `j`.
 |              * nearest: `i` or `j` whichever is nearest.
 |              * midpoint: (`i` + `j`) / 2.
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.quantile : Aggregating quantile for Series.
 |      pandas.DataFrame.quantile : Aggregating quantile for DataFrame.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([1, 2, 3, 4])
 |      >>> s.rolling(2).quantile(.4, interpolation='lower')
 |      0    NaN
 |      1    1.0
 |      2    2.0
 |      3    3.0
 |      dtype: float64
 |      
 |      >>> s.rolling(2).quantile(.4, interpolation='midpoint')
 |      0    NaN
 |      1    1.5
 |      2    2.5
 |      3    3.5
 |      dtype: float64
 |  
 |  rank(self, method: 'WindowingRankType' = 'average', ascending: 'bool' = True, pct: 'bool' = False, **kwargs)
 |      Calculate the rolling rank.
 |      
 |      .. versionadded:: 1.4.0 
 |      
 |      Parameters
 |      ----------
 |      method : {'average', 'min', 'max'}, default 'average'
 |          How to rank the group of records that have the same value (i.e. ties):
 |      
 |          * average: average rank of the group
 |          * min: lowest rank in the group
 |          * max: highest rank in the group
 |      
 |      ascending : bool, default True
 |          Whether or not the elements should be ranked in ascending order.
 |      pct : bool, default False
 |          Whether or not to display the returned rankings in percentile
 |          form.
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.rank : Aggregating rank for Series.
 |      pandas.DataFrame.rank : Aggregating rank for DataFrame.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([1, 4, 2, 3, 5, 3])
 |      >>> s.rolling(3).rank()
 |      0    NaN
 |      1    NaN
 |      2    2.0
 |      3    2.0
 |      4    3.0
 |      5    1.5
 |      dtype: float64
 |      
 |      >>> s.rolling(3).rank(method="max")
 |      0    NaN
 |      1    NaN
 |      2    2.0
 |      3    2.0
 |      4    3.0
 |      5    2.0
 |      dtype: float64
 |      
 |      >>> s.rolling(3).rank(method="min")
 |      0    NaN
 |      1    NaN
 |      2    2.0
 |      3    2.0
 |      4    3.0
 |      5    1.0
 |      dtype: float64
 |  
 |  sem(self, ddof: 'int' = 1, *args, **kwargs)
 |      Calculate the rolling standard error of mean.
 |      
 |      Parameters
 |      ----------
 |      ddof : int, default 1
 |          Delta Degrees of Freedom.  The divisor used in calculations
 |          is ``N - ddof``, where ``N`` represents the number of elements.
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.sem : Aggregating sem for Series.
 |      pandas.DataFrame.sem : Aggregating sem for DataFrame.
 |      
 |      Notes
 |      -----
 |      A minimum of one period is required for the calculation.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([0, 1, 2, 3])
 |      >>> s.rolling(2, min_periods=1).sem()
 |      0         NaN
 |      1    0.707107
 |      2    0.707107
 |      3    0.707107
 |      dtype: float64
 |  
 |  skew(self, **kwargs)
 |      Calculate the rolling unbiased skewness.
 |      
 |      Parameters
 |      ----------
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      scipy.stats.skew : Third moment of a probability density.
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.skew : Aggregating skew for Series.
 |      pandas.DataFrame.skew : Aggregating skew for DataFrame.
 |      
 |      Notes
 |      -----
 |      A minimum of three periods is required for the rolling calculation.
 |  
 |  std(self, ddof: 'int' = 1, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling standard deviation.
 |      
 |      Parameters
 |      ----------
 |      ddof : int, default 1
 |          Delta Degrees of Freedom.  The divisor used in calculations
 |          is ``N - ddof``, where ``N`` represents the number of elements.
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.4.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.4.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      numpy.std : Equivalent method for NumPy array.
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.std : Aggregating std for Series.
 |      pandas.DataFrame.std : Aggregating std for DataFrame.
 |      
 |      Notes
 |      -----
 |      The default ``ddof`` of 1 used in :meth:`Series.std` is different
 |      than the default ``ddof`` of 0 in :func:`numpy.std`.
 |      
 |      A minimum of one period is required for the rolling calculation.
 |      
 |      The implementation is susceptible to floating point imprecision as
 |      shown in the example below.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
 |      >>> s.rolling(3).std()
 |      0             NaN
 |      1             NaN
 |      2    5.773503e-01
 |      3    1.000000e+00
 |      4    1.000000e+00
 |      5    1.154701e+00
 |      6    2.580957e-08
 |      dtype: float64
 |  
 |  sum(self, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling sum.
 |      
 |      Parameters
 |      ----------
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.3.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.sum : Aggregating sum for Series.
 |      pandas.DataFrame.sum : Aggregating sum for DataFrame.
 |      
 |      Notes
 |      -----
 |      See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for extended documentation and performance considerations for the Numba engine.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([1, 2, 3, 4, 5])
 |      >>> s
 |      0    1
 |      1    2
 |      2    3
 |      3    4
 |      4    5
 |      dtype: int64
 |      
 |      >>> s.rolling(3).sum()
 |      0     NaN
 |      1     NaN
 |      2     6.0
 |      3     9.0
 |      4    12.0
 |      dtype: float64
 |      
 |      >>> s.rolling(3, center=True).sum()
 |      0     NaN
 |      1     6.0
 |      2     9.0
 |      3    12.0
 |      4     NaN
 |      dtype: float64
 |      
 |      For DataFrame, each sum is computed column-wise.
 |      
 |      >>> df = pd.DataFrame({"A": s, "B": s ** 2})
 |      >>> df
 |         A   B
 |      0  1   1
 |      1  2   4
 |      2  3   9
 |      3  4  16
 |      4  5  25
 |      
 |      >>> df.rolling(3).sum()
 |            A     B
 |      0   NaN   NaN
 |      1   NaN   NaN
 |      2   6.0  14.0
 |      3   9.0  29.0
 |      4  12.0  50.0
 |  
 |  var(self, ddof: 'int' = 1, *args, engine: 'str | None' = None, engine_kwargs: 'dict[str, bool] | None' = None, **kwargs)
 |      Calculate the rolling variance.
 |      
 |      Parameters
 |      ----------
 |      ddof : int, default 1
 |          Delta Degrees of Freedom.  The divisor used in calculations
 |          is ``N - ddof``, where ``N`` represents the number of elements.
 |      *args
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      engine : str, default None
 |          * ``'cython'`` : Runs the operation through C-extensions from cython.
 |          * ``'numba'`` : Runs the operation through JIT compiled code from numba.
 |          * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 |      
 |            .. versionadded:: 1.4.0
 |      
 |      engine_kwargs : dict, default None
 |          * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
 |          * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
 |            and ``parallel`` dictionary keys. The values must either be ``True`` or
 |            ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
 |            ``{'nopython': True, 'nogil': False, 'parallel': False}``
 |      
 |            .. versionadded:: 1.4.0
 |      
 |      **kwargs
 |          For NumPy compatibility and will not have an effect on the result.
 |      
 |      Returns
 |      -------
 |      Series or DataFrame
 |          Return type is the same as the original object with ``np.float64`` dtype.
 |      
 |      See Also
 |      --------
 |      numpy.var : Equivalent method for NumPy array.
 |      pandas.Series.rolling : Calling rolling with Series data.
 |      pandas.DataFrame.rolling : Calling rolling with DataFrames.
 |      pandas.Series.var : Aggregating var for Series.
 |      pandas.DataFrame.var : Aggregating var for DataFrame.
 |      
 |      Notes
 |      -----
 |      The default ``ddof`` of 1 used in :meth:`Series.var` is different
 |      than the default ``ddof`` of 0 in :func:`numpy.var`.
 |      
 |      A minimum of one period is required for the rolling calculation.
 |      
 |      The implementation is susceptible to floating point imprecision as
 |      shown in the example below.
 |      
 |      Examples
 |      --------
 |      >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
 |      >>> s.rolling(3).var()
 |      0             NaN
 |      1             NaN
 |      2    3.333333e-01
 |      3    1.000000e+00
 |      4    1.000000e+00
 |      5    1.333333e+00
 |      6    6.661338e-16
 |      dtype: float64
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __annotations__ = {'_attributes': 'list[str]'}
 |  
 |  __parameters__ = ()
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from BaseWindow:
 |  
 |  __getattr__(self, attr: 'str')
 |  
 |  __init__(self, obj: 'NDFrame', window=None, min_periods: 'int | None' = None, center: 'bool' = False, win_type: 'str | None' = None, axis: 'Axis' = 0, on: 'str | Index | None' = None, closed: 'str | None' = None, method: 'str' = 'single', *, selection=None)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __iter__(self)
 |  
 |  __repr__(self) -> 'str'
 |      Provide a nice str repr of our rolling object.
 |  
 |  validate(self) -> 'None'
 |  
 |  ----------------------------------------------------------------------
 |  Readonly properties inherited from BaseWindow:
 |  
 |  is_datetimelike
 |  
 |  win_type
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from BaseWindow:
 |  
 |  exclusions = frozenset()
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from pandas.core.base.SelectionMixin:
 |  
 |  __getitem__(self, key)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from pandas.core.base.SelectionMixin:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ndim
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from pandas.core.base.SelectionMixin:
 |  
 |  __orig_bases__ = (typing.Generic[~NDFrameT],)
 |  
 |  ----------------------------------------------------------------------
 |  Class methods inherited from typing.Generic:
 |  
 |  __class_getitem__(params) from builtins.type
 |  
 |  __init_subclass__(*args, **kwargs) from builtins.type
 |      This method is called when a class is subclassed.
 |      
 |      The default implementation does nothing. It may be
 |      overridden to extend subclasses.


Process finished with exit code 0
 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值