pandas.core.window.Rolling.max¶
Calculate the rolling maximum.
*args, **kwargs Arguments and keyword arguments to be passed into func.
- return
Series or DataFrame Return type is determined by the caller.
Examples¶
import pandas as pd
from numba import njit
@njit
def series_rolling_max():
series = pd.Series([4, 3, 5, 2, 6]) # Series of 4, 3, 5, 2, 6
out_series = series.rolling(3).max()
return out_series # Expect series of NaN, NaN, 5.0, 5.0, 6.0
print(series_rolling_max())
$ python ./series/rolling/series_rolling_max.py
0 NaN
1 NaN
2 5.0
3 5.0
4 6.0
dtype: float64
import pandas as pd
from numba import njit
@njit
def df_rolling_max():
df = pd.DataFrame({'A': [4, 3, 5, 2, 6], 'B': [-4, -3, -5, -2, -6]})
out_df = df.rolling(3).max()
# Expect DataFrame of
# {'A': [NaN, NaN, 5.0, 5.0, 6.0], 'B': [NaN, NaN, -3.0, -2.0, -2.0]}
return out_df
print(df_rolling_max())
$ python ./dataframe/rolling/dataframe_rolling_max.py
A B
0 NaN NaN
1 NaN NaN
2 5.0 -3.0
3 5.0 -2.0
4 6.0 -2.0
See also
- Series.rolling
Calling object with a Series.
- DataFrame.rolling
Calling object with a DataFrame.
- Series.max
Similar method for Series.
- DataFrame.max
Similar method for DataFrame.