Filtering rows on whether a column value is in a set of possible values, translated to Python's pandas.
Filtering rows using SQL's IN
in pandas
In SQL:
SELECT
*
FROM
table
WHERE column_1 IN ('A', 'B', 'C');
In pandas:
table[table['column_1']
.isin(['A', 'B', 'C'])]
Filtering rows using SQL's NOT IN
in pandas
In SQL:
SELECT
*
FROM
table
WHERE column_1 NOT IN ('A', 'B', 'C');
In pandas:
table[~table['column_1']
.isin(['A', 'B', 'C'])]
Not seeing anything different? Pay attention to the ~
, which inverts the specified filter!