| |
- right(source_string, length)
- DESCRIPTION:
Starting from the end of the input string, a substring is created with the
number of characters specified by the second parameter.
PARAMETERS:
source_string:
Required Argument.
Specifies a ColumnExpression of a string column or a string literal to
create substring from.
Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
Supported column types: CHAR, VARCHAR, and CLOB
length:
Required Argument.
Specifies the number of characters desired from the right side of the string. If this
number exceeds the number of characters in the source_string, then the original
source_string is returned.
This argument must be a positive integer.
Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
NOTE:
Function accepts positional arguments only.
ALTERNATE NAME:
td_right
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("dataframe", "admissions_train")
>>>
# Create a DataFrame on 'admissions_train' table.
>>> admissions_train = DataFrame("admissions_train")
>>> admissions_train
masters gpa stats programming admitted
id
22 yes 3.46 Novice Beginner 0
36 no 3.00 Advanced Novice 0
15 yes 4.00 Advanced Advanced 1
38 yes 2.65 Advanced Beginner 1
5 no 3.44 Novice Novice 0
17 no 3.83 Advanced Advanced 1
34 yes 3.85 Advanced Beginner 0
13 no 4.00 Advanced Novice 1
26 yes 3.57 Advanced Advanced 1
19 yes 1.98 Advanced Advanced 0
>>>
# Example truncates values in "programming" column to a length of 3.
# Import func from sqlalchemy to execute right function.
>>> from sqlalchemy import func
# Create a sqlalchemy Function object.
>>> right_func_ = func.right(admissions_train.programming.expression, 3)
>>>
# Pass the Function object as input to DataFrame.assign().
>>> df = admissions_train.assign(right_3_programming_=right_func_)
>>> print(df)
masters gpa stats programming admitted right_3_programming_
id
22 yes 3.46 Novice Beginner 0 ner
26 yes 3.57 Advanced Advanced 1 ced
5 no 3.44 Novice Novice 0 ice
17 no 3.83 Advanced Advanced 1 ced
13 no 4.00 Advanced Novice 1 ice
19 yes 1.98 Advanced Advanced 0 ced
36 no 3.00 Advanced Novice 0 ice
15 yes 4.00 Advanced Advanced 1 ced
34 yes 3.85 Advanced Beginner 0 ner
38 yes 2.65 Advanced Beginner 1 ner
>>>
|