Teradata Package for Python Function Reference on VantageCloud Lake - __sub__ - 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
- Language
- English (United States)
- Last Update
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Lake_2000
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.__sub__ = __sub__(self, other)
- Compute the difference between two ColumnExpressions using -
Note:
* Difference between two timestamp columns return value in seconds.
PARAMETERS:
other:
Required Argument.
Specifies Python literal or another ColumnExpression.
Types: ColumnExpression, Python literal
RETURNS:
ColumnExpression
RAISES:
Exception
A TeradataMlException gets thrown if SQLAlchemy
throws an exception when evaluating the expression.
EXAMPLES:
>>> load_example_data("burst", "finance_data")
>>> df = DataFrame("finance_data")
>>> df
start_time_column end_time_column expenditure income investment
id
1 67/06/30 07/07/10 415.0 451.0 180.0
4 67/06/30 07/07/10 448.0 493.0 192.0
2 67/06/30 07/07/10 421.0 465.0 179.0
3 67/06/30 07/07/10 434.0 485.0 185.0
5 67/06/30 07/07/10 459.0 509.0 211.0
>>> load_example_data("uaf", "Convolve2RealsLeft")
>>> timestamp_df = DataFrame("Convolve2RealsLeft")
>>> timestamp_df
row_seq row_i_time col_seq column_i_time A B C D
id
1 1 2018-08-08 08:02:00.000000 0 2018-08-08 08:00:00.000000 1.3 10.3 20.3 30.3
1 1 2018-08-08 08:02:00.000000 1 2018-08-08 08:02:00.000000 1.4 10.4 20.4 30.4
1 0 2018-08-08 08:00:00.000000 1 2018-08-08 08:02:00.000000 1.2 10.2 20.2 30.2
1 0 2018-08-08 08:00:00.000000 0 2018-08-08 08:00:00.000000 1.1 10.1 20.1 30.1
# Example 1: Subtract 100 from the income amount and assign the final amount
# to new column 'remaining_income'.
>>> df.assign(remaining_income=df.income - 100)
start_time_column end_time_column expenditure income investment remaining_income
id
3 67/06/30 07/07/10 434.0 485.0 185.0 385.0
2 67/06/30 07/07/10 421.0 465.0 179.0 365.0
1 67/06/30 07/07/10 415.0 451.0 180.0 351.0
5 67/06/30 07/07/10 459.0 509.0 211.0 409.0
4 67/06/30 07/07/10 448.0 493.0 192.0 393.0
# Example 2: Subtract investment amount from the income amount and assign the
# final amount to new column 'remaining_income'.
>>> df.assign(remaining_income=df.income - df.investment)
start_time_column end_time_column expenditure income investment remaining_income
id
3 67/06/30 07/07/10 434.0 485.0 185.0 300.0
2 67/06/30 07/07/10 421.0 465.0 179.0 286.0
1 67/06/30 07/07/10 415.0 451.0 180.0 271.0
5 67/06/30 07/07/10 459.0 509.0 211.0 298.0
4 67/06/30 07/07/10 448.0 493.0 192.0 301.0
# Example 3: Subtract 2 timestamp columns and assign to new column 'seconds'.
>>> timestamp_df.assign(seconds = timestamp_df.row_i_time-timestamp_df.column_i_time)
row_seq row_i_time col_seq column_i_time A B C D seconds
id
1 1 2018-08-08 08:02:00.000000 0 2018-08-08 08:00:00.000000 1.3 10.3 20.3 30.3 120.0
1 1 2018-08-08 08:02:00.000000 1 2018-08-08 08:02:00.000000 1.4 10.4 20.4 30.4 0.0
1 0 2018-08-08 08:00:00.000000 1 2018-08-08 08:02:00.000000 1.2 10.2 20.2 30.2 -120.0
1 0 2018-08-08 08:00:00.000000 0 2018-08-08 08:00:00.000000 1.1 10.1 20.1 30.1 0.0