Skip to content

Commit

Permalink
update 0.9.1 whatsnew to add where/mask commentary
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback authored and wesm committed Nov 15, 2012
1 parent 9867f8a commit c36a2f0
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions doc/source/v0.9.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,44 @@ New features
- DataFrame has new `where` and `mask` methods to select values according to a
given boolean mask (GH2109_, GH2151_)

.. ipython:: python
DataFrame currently supports slicing via a boolean vector the same length as the DataFrame (inside the `[]`).
The returned DataFrame has the same number of columns as the original, but is sliced on its index.

.. ipython:: python

df = DataFrame(np.random.randn(5, 3), columns = ['A','B','C'])

df

df[df['A'] > 0]

If a DataFrame is sliced with a DataFrame based boolean condition (with the same size as the original DataFrame),
then a DataFrame the same size (index and columns) as the original is returned, with
elements that do not meet the boolean condition as `NaN`. This is accomplished via
the new method `DataFrame.where`. In addition, `where` takes an optional `other` argument for replacement.

.. ipython:: python

df[df>0]

df.where(df>0)

df.where(df>0,-df)

Furthermore, `where` now aligns the input boolean condition (ndarray or DataFrame), such that partial selection
with setting is possible. This is analagous to partial setting via `.ix` (but on the contents rather than the axis labels)

.. ipython:: python

df = DataFrame(np.random.randn(5, 3))
df2 = df.copy()
df2[ df2[1:4] > 0 ] = 3
df2

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

df.mask(df < 0)
.. ipython:: python

df.mask(df<=0)

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

Expand Down

0 comments on commit c36a2f0

Please sign in to comment.