Teradata Package for Python Function Reference | 20.00 - contains - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Enterprise_2000
lifecycle
latest
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.contains = contains(self, pattern, case=True, na=None, **kw)
Search the pattern or substring in the column.
 
PARAMETERS:
    pattern:
        Required Argument.
        Specifies a literal value or ColumnExpression. Use ColumnExpression
        when comparison is done based on values inside ColumnExpression or
        based on a ColumnExpression function. Else, use literal value.
        Note:
             Argument supports regular expressions too.
        Types: str OR ColumnExpression
 
    case:
        Optional Argument.
        Specifies the case-sentivity match.
        When True, case-sensitive matches, otherwise case-sensitive does not matches.
        Default value: True
        Types: bool
 
    na:
        Optional Argument.
        Specifies an optional fill value for NULL values in the column
        Types: bool, str, or numeric python literal.
 
    **kw:
        Optional Argument.
        Specifies optional parameters to pass to regexp_substr
        match_arg:
            A string of characters to use for the match_arg parameter for REGEXP_SUBSTR
            See the Reference for more information about the match_arg parameter.
        Note:
             Specifying match_arg overrides the case parameter
 
 
RETURNS:
    A numeric Series of values where:
        - Nulls are replaced by the fill parameter
        - A 1 if the value matches the pattern or else 0
    The type of the series is upcasted to support the fill value, if specified.
 
EXAMPLES:
    >>> load_example_data("sentimentextractor", "additional_table")
    >>> df = DataFrame("additional_table")
    >>> df
                    polarity_strength
    sentiment_word
    'integral'                      1
    'eagerness'                     1
    'fearfully'                    -1
    irregular'                     -1
    'upgradable'                    1
    'rupture'                      -1
    'imperfect'                    -1
    'rejoicing'                     1
    'comforting'                    1
    'obstinate'                    -1
 
    >>> sentiment_word = df["sentiment_word"]
 
    # Example 1: Check if 'in' string is present or not in values in
    #            column 'sentiment_word'.
    >>> df.assign(drop_columns = True,
                 Name = sentiment_word,
                 has_in = sentiment_word.str.contains('in'))
               Name has_in
    0    'integral'      1
    1   'eagerness'      0
    2   'fearfully'      0
    3    irregular'      0
    4  'upgradable'      0
    5     'rupture'      0
    6   'imperfect'      0
    7   'rejoicing'      1
    8  'comforting'      1
    9   'obstinate'      1
 
     # Example 2: Check if accounts column contains 'Er' string by ignoring
     #            case sensitivity and specifying a literal for null values.
     >>> df.assign(drop_columns = True,
                   Name = sentiment_word,
                   has_er = sentiment_word.str.contains('ER', case=False, na = 'no value'))
                Name has_er
     0    'integral'      0
     1   'eagerness'      1
     2   'fearfully'      0
     3    irregular'      0
     4  'upgradable'      0
     5     'rupture'      0
     6   'imperfect'      1
     7   'rejoicing'      0
     8  'comforting'      0
     9   'obstinate'      0
 
    >>> load_example_data("dataframe", "sales")
    >>> df = DataFrame("sales")
    >>> df
                  Feb    Jan    Mar    Apr    datetime
    accounts
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017
    Jones LLC   200.0  150.0  140.0  180.0  04/01/2017
    Alpha Co    210.0  200.0  215.0  250.0  04/01/2017
 
    # Example 3: Get the all the accounts where accounts has 'Inc' string.
    >>> df[accounts.str.contains('Inc') == True]
                  Feb    Jan    Mar    Apr    datetime
    accounts
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017
 
    # Example 4: Get all the accounts where accounts does not
    #            have 'Inc' string.
    >>> df[accounts.str.contains('Inc') == False]
                 Feb  Jan  Mar  Apr    datetime
    accounts
    Jones LLC  200.0  150  140  180  04/01/2017
    Alpha Co   210.0  200  215  250  04/01/2017
 
    # Example 5: Get all the accounts where accounts has 'Inc' by
    #            specifying numeric literals for True (1).
    >>> df[accounts.str.contains('Inc') == 1]
                  Feb    Jan    Mar    Apr    datetime
    accounts
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017
 
    #Example 6: Get all the accounts where accounts has 'Inc' by
    #           specifying numeric literals for False (0).
    >>> df[accounts.str.contains('Inc') == 0]
                 Feb  Jan  Mar  Apr    datetime
    accounts
    Jones LLC  200.0  150  140  180  04/01/2017
    Alpha Co   210.0  200  215  250  04/01/2017
 
    >>> load_example_data("ntree", "employee_table")
    >>> df = DataFrame("employee_table")
    >>> df
           emp_name  mgr_id mgr_name
    emp_id
    200         Pat   100.0      Don
    300       Donna   100.0      Don
    400         Kim   200.0      Pat
    500        Fred   400.0      Kim
    100         Don     NaN       NA
 
    # Example 7: Get all the employees whose name has managers name.
    >>> df[df.emp_name.str.contains(df.mgr_name) == True]
    >>> df
           emp_name  mgr_id mgr_name
    emp_id
    300       Donna     100      Don