In [1]:
import pandas as pd
In [2]:
s = pd.Series(range(10))
In [3]:
print(s)
In [4]:
print(s.rolling(3))
In [5]:
print(type(s.rolling(3)))
In [6]:
print(s.rolling(3).sum())
In [7]:
print(s.rolling(2).sum())
In [8]:
print(s.rolling(4).sum())
In [9]:
print(s.rolling(3, center=True).sum())
In [10]:
print(s.rolling(4, center=True).sum())
In [11]:
print(s.rolling(3, min_periods=2).sum())
In [12]:
print(s.rolling(3, min_periods=1).sum())
In [13]:
df = pd.DataFrame({'a': range(10), 'b': range(10, 0, -1),
'c': range(10, 20), 'd': range(20, 10, -1)})
In [14]:
print(df.rolling(2).sum())
In [15]:
print(df.rolling(2, axis=1).sum())
In [16]:
print(s.rolling(3).mean())
In [17]:
print(s.rolling(3).agg(['sum', 'mean', 'skew', 'cov',
max, min,
lambda x: max(x) - min(x)]))