pydata/pandas — pull request #2337 by jreback (2012-11-23 21:42:36+00:00)
Title: Where/mask methods for Series

add where and mask methods for Series, analagous to DataFrame methods added for 0.9.1
passes all tests

where is equivalent to: ```s[cond].reindex_like(s).fillna(other)```

```
In [7]: s = pd.Series(np.random.rand(5))

In [8]: s
Out[8]:
0 0.638664
1 0.574688
2 0.460510
3 0.641840
4 0.044129

In [10]: s[0:2] = -s[0:2]

In [11]: s
Out[11]:
0 -0.638664
1 -0.574688
2 0.460510
3 0.641840
4 0.044129
```

boolean selection
```
In [12]: s[s>0]
Out[12]:
2 0.460510
3 0.641840
4 0.044129

In [13]: s.where(s>0)
Out[13]:
0 NaN
1 NaN
2 0.460510
3 0.641840
4 0.044129

In [14]: s.where(s>0,-s)
Out[14]:
0 0.638664
1 0.574688
2 0.460510
3 0.641840
4 0.044129

In [15]: s.mask(s<=0)
Out[15]:
0 NaN
1 NaN
2 0.460510
3 0.641840
4 0.044129

```

support setting as well (though not used anywhere explicity)
```
In [16]: s2 = s.copy()

In [17]: s2.where(s2>0,inplace=True)
Out[17]:
0 NaN
1 NaN
2 0.460510
3 0.641840
4 0.044129

In [18]: s2
Out[18]:
0 NaN
1 NaN
2 0.460510
3 0.641840
4 0.044129

```