PYNUMERIC( ) function

Returns a numeric value calculated by a function in an external Python script. Data processing in Python is external to Analytics.

Syntax

PYNUMERIC(PyFile,PyFunction, decimal <, field|value <,...n>>)

Parameters

Name Type Description
PyFile,PyFunction

character

The name of the Python script to run followed by a comma and then the name of the function that returns the value:

 "myScript,myFunction"

When specifying the Python script, omit the file extension. The function you call may call other functions within the script or within other scripts, however all scripts that run must be placed inside a folder in the PYTHONPATH system environment variable prior to running.

For more information, see Configuring Python for use with Analytics.

Note

Your PyFunction must return a Python numeric type.

decimal numeric The number of decimal places to include in the return value. Must be a positive integer.
field |value <,...n>

optional

character

numeric

datetime

logical

This list of fields, expressions, or literal values to use as arguments for the Python function. The values are passed into the function you call in the order you specify them.

You may include as many arguments as necessary to satisfy the function definition in the Python script.

Note

Use the ALLTRIM() function to remove any leading or trailing spaces from character input: ALLTRIM(str). For more information, see ALLTRIM( ) function.

Output

Numeric.

Examples

Basic examples

Returns 35.00:

PYNUMERIC("hello,get_nth_percent", 2, 80, 120, 30, 45, 30, 100, 35, 45)

External Python script that returns the value at the requested percentile from a dynamically sized list of values:

# hello.py content
from math import ceil
def get_nth_percent(percentage, *values):
    input_length = len(values)
    position = ceil((percentage/100.00) * input_length)
    return values[position-1]