Issue 1:
The .expanding() function is super cool. It's order of magnitude faster than

the obvious numpy alternative:

import numpy
import pandas
numpy.random.seed(123)
df = pandas.DataFrame((numpy.random.normal(0, 1, [10000, 2])), columns=['Value', 'Funny'])
%timeit method_2 = df.Value.expanding(0).apply(lambda x: x.sum())
%timeit method_1 = numpy.array([df.Value.iloc[range(j + 1)].sum() for j in range(df.shape[0])])

But it only works for univariate functions. Would it be possible to extend it to multiple columns while keeping the time efficiency? The idea would be to be able to compute functions involving several columns on expanding window of the data. Say something like:

def loc_fun(x, y):
return numpy.linalg.det(numpy.cov([x, y]))

df.expanding(3).apply(lambda x: loc_fun(x.Value, x.Funny))

faster than with numpy and list comprehension.

Expected Output

The result of say:

numpy.array([loc_fun(df.Value.iloc[range(j + 1)],df.Funny.iloc[range(j + 1)]) for j in range(3, df.shape[0])])

...but with the nicer speed;)

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-32-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 38.2.5
Cython: None
numpy: 1.13.3
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.5
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

[paste the output of pd.show_versions() here below this line]

Issue 2:
In #11603 (comment) (the main PR implementing the deferred API for rolling / expanding / ewm), we discussed how to specify table-wise applys. Groupby.apply(f) feeds the entire group (all columns) to f. For backwards-compatibility, .rolling(n).apply(f) needed to be column-wise.

#11603 (comment) mentions a possible API like what I added for .style

axis=0: apply to each column independently

axis=1: apply to each row independently

axis=None: apply the supplied function to the entire table

So it'd be df.rolling(n).apply(f, axis=None).

Do people like the axis=0 / 1 / None idiom? Is it obvious enough?

This is prompted by @josef-pkt's post on the mailinglist. Needing a rolling OLS.

An example:

In [2]: import numpy as np
...: import pandas as pd
...:
...: np.random.seed(0)
...: df = pd.DataFrame(np.random.randint(0, 10, size=(10, 2)), columns=["A", "B"])
...: df
...:
Out[2]:
A B
0 5 0
1 3 3
2 7 9
3 3 5
4 2 4
5 7 6
6 8 8
7 1 6
8 7 7
9 8 1

For a concrete example, get the table-wise max (this is equivalent to df.rolling(4).max().max(1))

In [10]: df.rolling(4).apply(np.max, axis=None)
Out[10]:
0 NaN
1 NaN
2 NaN
3 9.0
4 9.0
5 9.0
6 8.0
7 8.0
8 8.0
9 8.0
dtype: float64

A real example is something like a rolling OLS:

import statsmodels.api as sm
f = lambda x: sm.OLS.from_formula('A ~ B', data=x).fit() # wrong, but w/e

df.rolling(5).apply(f, axis=None)