isin() | Teradata Python Package - 17.00 - isin() - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

Use the isin() function to check for the presence of values in a column.

Example Prerequisites

>>> load_example_data("dataframe","admissions_train")
>>> df = DataFrame('admissions_train')
>>> df
   masters   gpa     stats programming  admitted
id
15     yes  4.00  Advanced    Advanced         1
7      yes  2.33    Novice      Novice         1
22     yes  3.46    Novice    Beginner         0
17      no  3.83  Advanced    Advanced         1
13      no  4.00  Advanced      Novice         1
38     yes  2.65  Advanced    Beginner         1
26     yes  3.57  Advanced    Advanced         1
5       no  3.44    Novice      Novice         0
34     yes  3.85  Advanced    Beginner         0
40     yes  3.95    Novice    Beginner         0

Example: Filter results where gpa values are in any of the specified values

>>> df[df.gpa.isin([4.0, 3.0, 2.0, 1.0, 3.5, 2.5, 1.5])]
   masters  gpa     stats programming  admitted
id
31     yes  3.5  Advanced    Beginner         1
6      yes  3.5  Beginner    Advanced         1
13      no  4.0  Advanced      Novice         1
4      yes  3.5  Beginner      Novice         1
29     yes  4.0    Novice    Beginner         0
15     yes  4.0  Advanced    Advanced         1
36      no  3.0  Advanced      Novice         0

Example: Filter results where the 'stats' values are neither 'Novice' nor 'Advanced'

>>> df[~df.stats.isin(['Novice', 'Advanced'])]
   masters   gpa     stats programming  admitted
id
1      yes  3.95  Beginner    Beginner         0
2      yes  3.76  Beginner    Beginner         0
8       no  3.60  Beginner    Advanced         1
4      yes  3.50  Beginner      Novice         1
6      yes  3.50  Beginner    Advanced         1