pydata/pandas — pull request #4781 by jreback (2013-09-09 03:05:55+00:00)
Title: ENH: Add axis and level keywords to where, so that the other argument can now be an alignable pandas object.

So traditionally a fillna that does the means of the columns is an apply operation

```
In [1]: df = DataFrame(np.random.randn(10,3))

In [2]: df.iloc[3:5,0] = np.nan

In [3]: df.iloc[4:6,1] = np.nan

In [4]: df.iloc[5:8,2] = np.nan

In [5]: df
Out[5]:
0 1 2
0 1.433548 0.544490 -0.145771
1 0.790451 0.938028 -0.168178
2 -0.875689 -3.024790 -1.790878
3 NaN -0.892199 -0.654873
4 NaN NaN -0.009731
5 -0.752477 NaN NaN
6 1.529992 -0.492140 NaN
7 1.577623 -0.314200 NaN
8 -0.169571 -1.585318 0.904505
9 -1.231798 -0.811622 -0.429850

In [6]: df.apply(lambda x: x.fillna(x.mean()),axis=0)
Out[6]:
0 1 2
0 1.433548 0.544490 -0.145771
1 0.790451 0.938028 -0.168178
2 -0.875689 -3.024790 -1.790878
3 0.287760 -0.892199 -0.654873
4 0.287760 -0.704719 -0.009731
5 -0.752477 -0.704719 -0.327825
6 1.529992 -0.492140 -0.327825
7 1.577623 -0.314200 -0.327825
8 -0.169571 -1.585318 0.904505
9 -1.231798 -0.811622 -0.429850
```

Adding ``axis`` and ``level`` arguments to ``where`` (which uses align under the hood), now enables the ``other`` object to be a Series/DataFrame (as well as a scalar) without a whole bunch of alignment/broadcasting

```
In [7]: df.where(pd.notnull(df),df.mean(),axis='columns')
Out[7]:
0 1 2
0 1.433548 0.544490 -0.145771
1 0.790451 0.938028 -0.168178
2 -0.875689 -3.024790 -1.790878
3 0.287760 -0.892199 -0.654873
4 0.287760 -0.704719 -0.009731
5 -0.752477 -0.704719 -0.327825
6 1.529992 -0.492140 -0.327825
7 1.577623 -0.314200 -0.327825
8 -0.169571 -1.585318 0.904505
9 -1.231798 -0.811622 -0.429850
```