Teradata Package for Python Function Reference | 20.00 - regr_count - 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 - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.window.regr_count = regr_count(expression)
- DESCRIPTION:
Function returns the count of all non-null data pairs of the dependent and
independent variable arguments over the specified window. The function
considers ColumnExpression as a dependent variable and "expression" as
an independent variable.
PARAMETERS:
expression:
Required Argument.
Specifies a ColumnExpression of a column or name of the column or a
literal representing an independent variable for the regression.
An independent variable is a treatment: something that is varied under
your control to test the behavior of another variable.
Types: ColumnExpression OR int OR float OR str
RETURNS:
* teradataml DataFrame - When aggregate is executed using window created
on teradataml DataFrame.
* ColumnExpression, also known as, teradataml DataFrameColumn - When aggregate is
executed using window created on ColumnExpression.
RAISES:
RuntimeError - If column does not support the aggregate operation.
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
>>>
# Note:
# In the examples here, ColumnExpression is passed as input. User can
# choose to pass column name instead of the ColumnExpression.
# Example 1: Calculate the total number of non-null data pairs with dependent
# variable as column 'admitted' and independent variable as 'gpa',
# in a Rolling window, partitioned over 'programming'.
# Create a Rolling window on 'gpa'.
>>> window = admissions_train.gpa.window(partition_columns="programming",
... window_start_point=-2,
... window_end_point=0)
>>>
# Execute regr_count() on the Rolling window and attach it to the DataFrame.
# Note: DataFrame.assign() allows combining multiple window aggregate
# operations in one single call. In this example, we are executing
# regr_count() along with max() window aggregate operations.
>>> df = admissions_train.assign(regr_count_gpa=window.regr_count(admissions_train.admitted),
... max_gpa=window.max())
>>> df
masters gpa stats programming admitted max_gpa regr_count_gpa
id
2 yes 3.76 Beginner Beginner 0 3.95 3
21 no 3.87 Novice Beginner 1 3.87 3
40 yes 3.95 Novice Beginner 0 3.95 3
22 yes 3.46 Novice Beginner 0 3.95 3
35 no 3.68 Novice Beginner 1 3.75 3
29 yes 4.00 Novice Beginner 0 4.00 3
11 no 3.13 Advanced Advanced 1 3.13 1
28 no 3.93 Advanced Advanced 1 3.93 2
16 no 3.70 Advanced Advanced 1 3.93 3
8 no 3.60 Beginner Advanced 1 3.93 3
>>>
# Example 2: Calculate the count of the column 'admitted' for all non-null
# data pairs with dependent variable as all other columns,
# in an Expanding window, partitioned over 'programming',
# and order by 'id' in descending order.
# Create an Expanding window on DataFrame.
>>> window = admissions_train.window(partition_columns="programming",
... order_columns=admissions_train.id.desc(),
... window_start_point=None,
... window_end_point=0)
>>>
# Execute regr_count() on the Expanding window.
>>> df = window.regr_count(admissions_train.admitted)
>>> df
masters gpa stats programming admitted admitted_regr_count gpa_regr_count id_regr_count
id
38 yes 2.65 Advanced Beginner 1 3 3 3
34 yes 3.85 Advanced Beginner 0 5 5 5
32 yes 3.46 Advanced Beginner 0 6 6 6
31 yes 3.50 Advanced Beginner 1 7 7 7
22 yes 3.46 Novice Beginner 0 9 9 9
21 no 3.87 Novice Beginner 1 10 10 10
28 no 3.93 Advanced Advanced 1 1 1 1
27 yes 3.96 Advanced Advanced 0 2 2 2
26 yes 3.57 Advanced Advanced 1 3 3 3
25 no 3.96 Advanced Advanced 1 4 4 4
>>>
# Example 3: Calculate the regression count of the column 'gpa' for
# all non-null data pairs with dependent variable as all
# other columns, which are grouped by 'masters' and 'gpa'
# in a Contracting window, partitioned over 'masters' and
# order by 'masters' with nulls listed last.
# Perform group_by() operation on teradataml DataFrame.
>>> group_by_df = admissions_train.groupby(["masters", "gpa"])
# Create a Contracting window on teradataml DataFrameGroupBy object.
>>> window = group_by_df.window(partition_columns="masters",
... order_columns="masters",
... nulls_first=False,
... window_start_point=-5,
... window_end_point=None)
# Execute regr_count() on the Contracting window.
>>> window.regr_avgx(admissions_train.gpa)
masters gpa gpa_regr_count
0 no 3.13 8
1 no 3.83 10
2 no 3.82 11
3 no 3.55 12
4 no 1.87 14
5 no 3.00 15
6 yes 3.50 6
7 yes 4.00 7
8 yes 3.76 8
9 yes 3.90 9
>>>