modin.pandas.Resampler.mean¶
- Resampler.mean(numeric_only: bool = False, *args: Any, **kwargs: Any) Union[DataFrame, Series] [source]¶
Compute mean of resample bins.
- Parameters:
numeric_only (bool, default False) – Include only float, int, boolean columns.
engine (str, default None) – This parameter is ignored in Snowpark pandas. The execution engine will always be Snowflake.
engine_kwargs (dict, default None) – This parameter is ignored in Snowpark pandas. The execution engine will always be Snowflake.
- Returns:
Computed mean of values within each resample bin.
- Return type:
Examples
For Series:
>>> lst1 = pd.date_range('2020-01-01', periods=4, freq='1D') >>> ser1 = pd.Series([1, 2, 3, 4], index=lst1) >>> ser1 2020-01-01 1 2020-01-02 2 2020-01-03 3 2020-01-04 4 Freq: None, dtype: int64
>>> ser1.resample('2D').mean() 2020-01-01 1.5 2020-01-03 3.5 Freq: None, dtype: float64
>>> lst2 = pd.date_range('2020-01-01', periods=4, freq='S') >>> ser2 = pd.Series([1, 2, np.nan, 4], index=lst2) >>> ser2 2020-01-01 00:00:00 1.0 2020-01-01 00:00:01 2.0 2020-01-01 00:00:02 NaN 2020-01-01 00:00:03 4.0 Freq: None, dtype: float64
>>> ser2.resample('2S').mean() 2020-01-01 00:00:00 1.5 2020-01-01 00:00:02 4.0 Freq: None, dtype: float64
For DataFrame:
>>> df1 = pd.DataFrame( ... {'A': [1, 1, 2, 1, 2], 'B': [np.nan, 2, 3, 4, 5]}, ... index=pd.date_range('2020-01-01', periods=5, freq='1D')) >>> df1 A B 2020-01-01 1 NaN 2020-01-02 1 2.0 2020-01-03 2 3.0 2020-01-04 1 4.0 2020-01-05 2 5.0
>>> df1.resample('2D').mean() A B 2020-01-01 1.0 2.0 2020-01-03 1.5 3.5 2020-01-05 2.0 5.0
>>> df1.resample('2D')['B'].mean() 2020-01-01 2.0 2020-01-03 3.5 2020-01-05 5.0 Freq: None, Name: B, dtype: float64
>>> df2 = pd.DataFrame( ... {'A': [1, 2, 3, np.nan], 'B': [np.nan, np.nan, 3, 4]}, ... index=pd.date_range('2020-01-01', periods=4, freq='1S')) >>> df2 A B 2020-01-01 00:00:00 1.0 NaN 2020-01-01 00:00:01 2.0 NaN 2020-01-01 00:00:02 3.0 3.0 2020-01-01 00:00:03 NaN 4.0
>>> df2.resample('2S').mean() A B 2020-01-01 00:00:00 1.5 NaN 2020-01-01 00:00:02 3.0 3.5