contains() Method | Teradata Python Package - 17.00 - contains() Method - 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)

The contains() method tests if the given regular expression pattern matches string values in the column.

Example

>>> df = DataFrame('sales')
>>> accounts = df['accounts']
>>> df.assign(drop_columns = True, Accounts = accounts, has_llc = accounts.str.contains('LLC'))
     Accounts has_llc
0    Alpha Co       0
1    Blue Inc       0
2  Yellow Inc       0
3   Jones LLC       1
4     Red Inc       0
5  Orange Inc       0

Examples using the case parameter

The contains() method has a case parameter to toggle case-sensitive matching on or off. The default value is on.

>>> df = DataFrame('sales')
>>> accounts = df['accounts']
>>> df.assign(drop_columns = True, Accounts = accounts, has_llc = accounts.str.contains('llc', case=True))
     Accounts has_llc
0    Blue Inc       0
1    Alpha Co       0
2   Jones LLC       0
3  Yellow Inc       0
4  Orange Inc       0
5     Red Inc       0
>>> df.assign(drop_columns = True, Accounts = accounts, has_llc = accounts.str.contains('llc', case=False))
     Accounts has_llc
0    Blue Inc       0
1    Alpha Co       0
2   Jones LLC       1
3  Yellow Inc       0
4  Orange Inc       0
5     Red Inc       0

Example using the na parameter

Use the na parameter to specify an optional fill value for columns that have a NULL value. You can pass numeric, string, or bool literals.

>>> df = DataFrame('employee_info')
>>> df
            first_name marks   dob joined_date
employee_no                                  
112               None  None  None    18/12/05
101              abcde  None  None    02/12/05
100               abcd  None  None        None
>>> df.assign(has_name = df.first_name.str.contains('abcd', na = 'FNU'))
            first_name marks   dob joined_date has_name
employee_no                                           
112               None  None  None    18/12/05      FNU
101              abcde  None  None    02/12/05        1
100               abcd  None  None        None        1