Skip to content

Commit c36a2f0

Browse files
jrebackwesm
authored andcommitted
update 0.9.1 whatsnew to add where/mask commentary
1 parent 9867f8a commit c36a2f0

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

doc/source/v0.9.1.txt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,44 @@ New features
4242
- DataFrame has new `where` and `mask` methods to select values according to a
4343
given boolean mask (GH2109_, GH2151_)
4444

45-
.. ipython:: python
45+
DataFrame currently supports slicing via a boolean vector the same length as the DataFrame (inside the `[]`).
46+
The returned DataFrame has the same number of columns as the original, but is sliced on its index.
47+
48+
.. ipython:: python
49+
50+
df = DataFrame(np.random.randn(5, 3), columns = ['A','B','C'])
51+
52+
df
53+
54+
df[df['A'] > 0]
55+
56+
If a DataFrame is sliced with a DataFrame based boolean condition (with the same size as the original DataFrame),
57+
then a DataFrame the same size (index and columns) as the original is returned, with
58+
elements that do not meet the boolean condition as `NaN`. This is accomplished via
59+
the new method `DataFrame.where`. In addition, `where` takes an optional `other` argument for replacement.
60+
61+
.. ipython:: python
62+
63+
df[df>0]
64+
65+
df.where(df>0)
66+
67+
df.where(df>0,-df)
68+
69+
Furthermore, `where` now aligns the input boolean condition (ndarray or DataFrame), such that partial selection
70+
with setting is possible. This is analagous to partial setting via `.ix` (but on the contents rather than the axis labels)
71+
72+
.. ipython:: python
4673

47-
df = DataFrame(np.random.randn(5, 3))
74+
df2 = df.copy()
75+
df2[ df2[1:4] > 0 ] = 3
76+
df2
4877

49-
df.where(df > 0, -df)
78+
`DataFrame.mask` is the inverse boolean operation of `where`.
5079

51-
df.mask(df < 0)
80+
.. ipython:: python
5281

82+
df.mask(df<=0)
5383

5484
- Enable referencing of Excel columns by their column names (GH1936_)
5585

0 commit comments

Comments
 (0)