Teradata Package for Python Function Reference - 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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
nvp

 
Functions
       
nvp(instring, name_to_search, name_delimiters, value_delimiters, occurrence)
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:
    instring:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        containing the name-value pairs separated by multi-byte delimiters..
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
 
    name_to_search:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        whose instring value NVP returns.
 
    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.
        The default value is & (ampersand).
 
    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.
        The default value is = (equal sign).
 
    occurrence:
        Optional Argument.
        Specifies the number of occurrences of name_to_search that NVP searches for.
        The default value is 1.
 
NOTE:
    Function accepts positional arguments only.
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "employee_info")
    >>>
 
    # Create a DataFrame on 'employee_info' table.
    >>> employee_info = DataFrame("employee_info")
    >>> employee_info
                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
    >>>
 
    # Import func from sqlalchemy to execute nvp function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    # Retrieve nvp value for string literal "entree:orange chicken#entree2:honey salmon"
    # and return a new teradataml DataFrame by adding retrieved nvp value as a column
    # to admission_train
    >>> nvp_func_ = func.NVP('entree:orange chicken#entree2:honey salmon', 'entree','#', ':', 1)
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = employee_info.assign(nvp_literal_=nvp_func_)
    >>> print(df)
                first_name marks   dob joined_date    nvp_literal_
    employee_no
    101              abcde  None  None    02/12/05  orange chicken
    100               abcd  None  None        None  orange chicken
    112               None  None  None    18/12/05  orange chicken
    >>>