Skip to content

Commit

Permalink
Cookbook: filter to top x%. Closes #47.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Sep 4, 2015
1 parent 3ccd5e7 commit b578e3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.7.0
-----

* Cookbook: filter to top x%. (#47)
* Cookbook: fuzzy string search example. (#176)
* Values to coerce to true/false can now be overridden for BooleanType.
* Values to coerce to null can now be overridden for all ColumnType subclasses. (#206)
Expand Down
14 changes: 11 additions & 3 deletions docs/cookbook/filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ This snippet filters the dataset to incomes between 100,000 and 200,000.
.. code-block:: python
new_table = table.where(lambda row: 100000 < row['income'] < 200000)
new_table = table.where(lambda row: 100000 < row['income'] < 200000)
Filter to top x%
================
To filter a dataset to the top 10% percent of values we first compute the percentiles for the column and then use the result in the :meth:`.Table.where` truth test:
.. code-block:: python
percentiles = table.columns['salary'].percentiles()
top_ten_percent = table.where(lambda r: r['salary'] >= percentiles[90])
Random sample
=============
Expand All @@ -61,5 +71,3 @@ With can also get an ordered sample by simply using the :code:`step` parameter o
.. code-block:: python
sampled = table.limit(step=10)

0 comments on commit b578e3b

Please sign in to comment.