Teradata Package for Python Function Reference on VantageCloud Lake - nvp - 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 on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
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_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.nvp = nvp(name_to_search, name_delimiters='&', value_delimiters='=', occurrence=1)
DESCRIPTION:
    Function extracts the value of a name-value pair where the name in the pair matches
    the name and the number of the "occurrence" specified.
 
PARAMETERS:
    name_to_search:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        whose instring value NVP returns.
        Types: ColumnExpression, str
 
    name_delimiters:
        Optional Argument.
        Specifies the multi-byte delimiters used to separate name-value pairs.
        Delimiters can contain any characters. They are separated from each
        other in the string by spaces. If a space is used as part of a delimiter,
        it must be escaped using a backslash (\). The maximum length of any
        delimiter is 10, and the maximum size of this parameter is 32.
        Default value: '&' (ampersand).
        Types: str
 
    value_delimiters:
        Optional Argument.
        Specifies the multi-byte delimiters used to associate a name to its value in a
        name-value pair.
        Delimiters can contain any characters. They are separated from each other in the
        string by spaces. If a space is used as part of a delimiter, it must be escaped
        using a backslash (\). The maximum length of any delimiter is 10, and the
        maximum size of this parameter is 32.
        Default value: '=' (equal sign).
        Types: str
 
    occurrence:
        Optional Argument.
        Specifies the number of occurrences of name_to_search that NVP searches for.
        Default value: 1.
        Types: int
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    DataFrameColumn
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "employee_info")
 
    # Create a DataFrame on 'employee_info' table.
    >>> df = DataFrame("employee_info")
    >>> print(df)
                first_name marks   dob joined_date
    employee_no
    101              abcde  None  None    02/12/05
    100               abcd  None  None        None
    112               None  None  None    18/12/05
 
    # Create a column 'nvp_col' for specifying string literal 'entree:orange chicken#entree2:honey salmon'
    >>> df = df.assign(nvp_col = 'entree:orange chicken#entree2:honey salmon')
    >>> print(df)
                first_name marks   dob joined_date    nvp_literal_                                     nvp_col
    employee_no
    112               None  None  None    18/12/05  orange chicken  entree:orange chicken#entree2:honey salmon
    100               abcd  None  None        None  orange chicken  entree:orange chicken#entree2:honey salmon
    101              abcde  None  None    02/12/05  orange chicken  entree:orange chicken#entree2:honey salmon
 
    # Example 1: Retrieve nvp value for "nvp_col" and pass it as input to DataFrame.assign().
    >>> res = df.assign(col= df.nvp_col.nvp('entree','#', ':', 1))
    >>> print(res)
                first_name marks   dob joined_date                                     nvp_col             col
    employee_no
    112               None  None  None    18/12/05  entree:orange chicken#entree2:honey salmon  orange chicken
    100               abcd  None  None        None  entree:orange chicken#entree2:honey salmon  orange chicken
    101              abcde  None  None    02/12/05  entree:orange chicken#entree2:honey salmon  orange chicken
 
    # Example 2: Executed nvp() function on "nvp_col" column and filtered computed
    #            values which are equal to 'orange chicken'.
    >>> print(df[df.nvp_col.nvp('entree','#', ':', 1) == "orange chicken"])
                first_name marks   dob joined_date                                     nvp_col
    employee_no
    100               abcd  None  None        None  entree:orange chicken#entree2:honey salmon
    101              abcde  None  None    02/12/05  entree:orange chicken#entree2:honey salmon
    112               None  None  None    18/12/05  entree:orange chicken#entree2:honey salmon