Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - trunc - 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
- 17.20
- Publication Date
- November 2022
- Content Type
- Programming Reference
- Publication ID
- B700-4500-112K
- ft:locale
- en-US
- ft:lastEdition
- 2024-02-21
- ft:sourceId
- FTML
- dita:id
- TeradataPython_FxRef_Lake_1720
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.trunc = trunc(expression=0)
- DESCRIPTION:
Function returns the values in column truncated places_value (expression) places to the right or left
of the decimal point.
trunc() functions as follows:
* It truncates places_value places to the right of the decimal point if
places_value is positive.
* It truncates (makes 0) places_value places to the left of the decimal
point if places_value is negative.
* It truncates to 0 places if places_value is zero or is omitted.
* If numeric_value or places_value is NULL, the function returns NULL.
PARAMETERS:
expression:
Optional Argument.
Specifies a ColumnExpression of a numeric column or a numeric constant value.
This decides the number of places to truncate.
Format for the argument: '<dataframe>.<dataframe_column>'.
Default Value: 0
Types: ColumnExpression, int
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
DataFrameColumn
EXAMPLES:
# Load the data to execute the example.
>>> load_example_data("dataframe", "admissions_train")
>>>
# Create a DataFrame on 'admissions_train' table.
>>> df = DataFrame("admissions_train").iloc[:4]
>>> print(df)
masters gpa stats programming admitted
id
3 no 3.70 Novice Beginner 1
4 yes 3.50 Beginner Novice 1
2 yes 3.76 Beginner Beginner 0
1 yes 3.95 Beginner Beginner 0
# Example 1: Execute trunc() function and pass it as input to DataFrame.assign().
>>> res = df.assign(col = df.gpa.trunc(),
col_1 = df.gpa.trunc(1))
>>> print(res)
masters gpa stats programming admitted col col_1
id
3 no 3.70 Novice Beginner 1 3.0 3.7
4 yes 3.50 Beginner Novice 1 3.0 3.5
2 yes 3.76 Beginner Beginner 0 3.0 3.7
1 yes 3.95 Beginner Beginner 0 3.0 3.9
# Example 2: Executed trunc() function on "gpa" column and filtered computed values
# which are greater than 3.7.
>>> print(df[df.gpa.trunc(1) > 3.7])
masters gpa stats programming admitted
id
1 yes 3.95 Beginner Beginner 0