turicreate.SFrame.filter_by

SFrame.filter_by(values, column_name, exclude=False)

Filter an SFrame by values inside an iterable object. Result is an SFrame that only includes (or excludes) the rows that have a column with the given column_name which holds one of the values in the given values SArray. If values is not an SArray, we attempt to convert it to one before filtering.

Parameters:
values : SArray | list | numpy.ndarray | pandas.Series | str

The values to use to filter the SFrame. The resulting SFrame will only include rows that have one of these values in the given column.

column_name : str

The column of the SFrame to match with the given values.

exclude : bool

If True, the result SFrame will contain all rows EXCEPT those that have one of values in column_name.

Returns:
out : SFrame

The filtered SFrame.

Examples

>>> sf = turicreate.SFrame({'id': [1, 2, 3, 4],
...                      'animal_type': ['dog', 'cat', 'cow', 'horse'],
...                      'name': ['bob', 'jim', 'jimbob', 'bobjim']})
>>> household_pets = ['cat', 'hamster', 'dog', 'fish', 'bird', 'snake']
>>> sf.filter_by(household_pets, 'animal_type')
+-------------+----+------+
| animal_type | id | name |
+-------------+----+------+
|     dog     | 1  | bob  |
|     cat     | 2  | jim  |
+-------------+----+------+
[2 rows x 3 columns]
>>> sf.filter_by(household_pets, 'animal_type', exclude=True)
+-------------+----+--------+
| animal_type | id |  name  |
+-------------+----+--------+
|    horse    | 4  | bobjim |
|     cow     | 3  | jimbob |
+-------------+----+--------+
[2 rows x 3 columns]