contains() Method | Teradata Package for Python - contains() Method - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Use the contains() method to test if the given regular expression pattern matches string values in the column.

Example 1: Test if column contains a given expression

>>> 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

Example 2: Test using the case parameter

Uses the case parameter to toggle case-sensitive matching on or off. The default value is on.

>>> df = DataFrame('sales')
>>> accounts = df['accounts']

Example 2.1: Test when case is set to True.

>>> 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

Example 2.1: Test when case is set to False.

>>> 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 3: Test 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