Teradata Package for Python Function Reference - csum - 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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.csum = csum(self, sort_columns, drop_columns=False)
DESCRIPTION:
    Returns column-wise cumulative sum value for rows in the partition
    of the dataframe.
    Note:
        csum does not support below type of columns.
            * BLOB
            * BYTE
            * CHAR
            * CLOB
            * DATE
            * PERIOD_DATE
            * PERIOD_TIME
            * PERIOD_TIMESTAMP
            * TIME
            * TIMESTAMP
            * VARBYTE
            * VARCHAR            
 
PARAMETERS:
    sort_columns:
        Required Argument.
        Specifies the columns to use for sorting.
        Note:
            "sort_columns" does not support CLOB and BLOB type of
            columns.
        Types: str (or) ColumnExpression (or) List of strings(str)
               or ColumnExpressions
 
    drop_columns:
        Optional Argument.
        Specifies whether to retain all the input DataFrame columns
        in the output or not. When set to False, columns from input
        DataFrame are retained, dropped otherwise.
        Default Value: False
        Types: bool
 
RAISES:
    TeradataMlException, TypeError
 
RETURNS:
    teradataml DataFrame.
 
EXAMPLES:
    # Load the data to run the example.
    >>> from teradataml import load_example_data
    >>> load_example_data("dataframe","sales")
 
    # Create teradataml dataframe.
    >>> df = DataFrame.from_table('sales')
    >>> print(df)
                  Feb    Jan    Mar    Apr    datetime
    accounts
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017
    Jones LLC   200.0  150.0  140.0  180.0  04/01/2017
    Alpha Co    210.0  200.0  215.0  250.0  04/01/2017
    >>>
 
    # Sorts the Data on column accounts in ascending order and
    # calculates cumulative sum.
    >>> df.csum(df.accounts)
                  Feb    Jan    Mar    Apr    datetime  csum_Feb  csum_Jan  csum_Mar  csum_Apr
    accounts
    Jones LLC   200.0  150.0  140.0  180.0  04/01/2017     500.0       400       450       531
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017     910.0       550       590       781
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017    1000.0       550       590       781
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017     710.0       400       450       781
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017     300.0       250       310       351
    Alpha Co    210.0  200.0  215.0  250.0  04/01/2017     210.0       200       215       250
    >>>
 
    # Sorts the Data on column accounts in ascending order and column
    # Feb in descending order, then calculates cumulative sum by dropping
    # the input DataFrame columns.
    >>> df.csum(sort_columns=[df.accounts, df.Feb.desc()], drop_columns=True)
       csum_Feb  csum_Jan  csum_Mar  csum_Apr
    0     500.0       400       450       531
    1     910.0       550       590       781
    2    1000.0       550       590       781
    3     710.0       400       450       781
    4     300.0       250       310       351
    5     210.0       200       215       250
    >>>