Teradata Package for Python Function Reference - mode - 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.DataFrameGroupByTime.mode = mode(self)
DESCRIPTION:
    Returns the column-wise mode of all values in each group. In the event of a tie between two or more
    values from column, a row per result is returned. mode() is a single-threaded function.
 
    Note:
        1. This function is valid only on columns with numeric types.
        2. Null values are not included in the result computation.
 
PARAMETERS:
    None.
 
RETURNS:
    teradataml DataFrame object with mode() operation performed.
 
RAISES:
    1. TDMLDF_AGGREGATE_FAILED - If mode() operation fails to
        return mode value of columns in the teradataml DataFrame.
 
        Possible error message:
        Unable to perform 'mode()' on the teradataml DataFrame.
 
    2. TDMLDF_AGGREGATE_COMBINED_ERR - If the mode() operation
        doesn't support all the columns in the teradataml DataFrame.
 
        Possible error message:
        No results. Below is/are the error message(s):
        All selected columns [(col2 -  PERIOD_TIME), (col3 -
        BLOB)] is/are unsupported for 'mode' operation.
 
EXAMPLES :
    >>> # Load the example datasets.
    ... load_example_data("dataframe", ["ocean_buoys", "ocean_buoys_seq", "ocean_buoys_nonpti"])
    >>>
 
    #
    # Example 1: Executing mode function on DataFrame created on non-sequenced PTI table.
    #
    >>> # Create the required DataFrames.
    ... # DataFrame on non-sequenced PTI table
    ... ocean_buoys = DataFrame("ocean_buoys")
    >>> # Check DataFrame columns and let's peek at the data
    ... ocean_buoys.columns
    ['buoyid', 'TD_TIMECODE', 'temperature', 'salinity']
    >>> ocean_buoys.head()
                           TD_TIMECODE  temperature  salinity
    buoyid
    0       2014-01-06 08:10:00.000000        100.0        55
    0       2014-01-06 08:08:59.999999          NaN        55
    1       2014-01-06 09:01:25.122200         77.0        55
    1       2014-01-06 09:03:25.122200         79.0        55
    1       2014-01-06 09:01:25.122200         70.0        55
    1       2014-01-06 09:02:25.122200         71.0        55
    1       2014-01-06 09:03:25.122200         72.0        55
    0       2014-01-06 08:09:59.999999         99.0        55
    0       2014-01-06 08:00:00.000000         10.0        55
    0       2014-01-06 08:10:00.000000         10.0        55
 
    >>> ocean_buoys_grpby1 = ocean_buoys.groupby_time(timebucket_duration="10m",
    ...                                               value_expression="buoyid", fill="NULLS")
    >>> ocean_buoys_grpby1.mode().sort(["TIMECODE_RANGE", "buoyid"])
                                          TIMECODE_RANGE  GROUP BY TIME(MINUTES(10))  buoyid  mode_temperature  mode_salinity
    0  ('2014-01-06 08:00:00.000000+00:00', '2014-01-...                      106033       0                99             55
    1  ('2014-01-06 08:00:00.000000+00:00', '2014-01-...                      106033       0                10             55
    2  ('2014-01-06 08:10:00.000000+00:00', '2014-01-...                      106034       0               100             55
    3  ('2014-01-06 08:10:00.000000+00:00', '2014-01-...                      106034       0                10             55
    4  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                79             55
    5  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                70             55
    6  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                72             55
    7  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                78             55
    8  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                71             55
    9  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1                77             55
 
    #
    # Example 2: Executing mode function on ocean_buoys_seq DataFrame created on sequenced PTI table.
    #            Table has few columns incompatible for mode() operation 'dates' and 'TD_TIMECODE',
    #            while executing this mode() incompatible columns are ignored.
    #
    >>> # DataFrame on sequenced PTI table
    ... ocean_buoys_seq = DataFrame("ocean_buoys_seq")
    >>> # Check DataFrame columns and let's peek at the data
    ... ocean_buoys_seq.columns
    ['TD_TIMECODE', 'TD_SEQNO', 'buoyid', 'salinity', 'temperature', 'dates']
    >>> ocean_buoys_seq.head()
                           TD_TIMECODE  TD_SEQNO  salinity  temperature       dates
    buoyid
    0       2014-01-06 08:00:00.000000        26        55         10.0  2016-02-26
    0       2014-01-06 08:08:59.999999        18        55          NaN  2015-06-18
    1       2014-01-06 09:02:25.122200        24        55         78.0  2015-12-24
    1       2014-01-06 09:01:25.122200        23        55         77.0  2015-11-23
    1       2014-01-06 09:02:25.122200        12        55         71.0  2014-12-12
    1       2014-01-06 09:03:25.122200        13        55         72.0  2015-01-13
    1       2014-01-06 09:01:25.122200        11        55         70.0  2014-11-11
    0       2014-01-06 08:10:00.000000        19        55         10.0  2015-07-19
    0       2014-01-06 08:09:59.999999        17        55         99.0  2015-05-17
    0       2014-01-06 08:10:00.000000        27        55        100.0  2016-03-27
 
    >>> ocean_buoys_seq_grpby1 = ocean_buoys_seq.groupby_time(timebucket_duration="MINUTES(10)",
    ...                                                       value_expression="buoyid", fill="NULLS")
    >>> ocean_buoys_seq_grpby1.mode().sort(["TIMECODE_RANGE", "buoyid"])
                                          TIMECODE_RANGE  GROUP BY TIME(MINUTES(10))  buoyid  mode_TD_SEQNO  mode_salinity  mode_temperature
    0  ('2014-01-06 08:00:00.000000+00:00', '2014-01-...                      106033       0             17             55                10
    1  ('2014-01-06 08:10:00.000000+00:00', '2014-01-...                      106034       0             19             55                10
    2  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                      106039       1             11             55                70
    3  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44              7             55                43
    4  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44             21             55                43
    5  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44             20             55                43
    6  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44              4             55                43
    7  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44              9             55                43
    8  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44              8             55                43
    9  ('2014-01-06 10:00:00.000000+00:00', '2014-01-...                      106045      44              5             55                43
 
    #
    # Example 3: Executing mode function on DataFrame created on NON-PTI table.
    #
    >>> # DataFrame on NON-PTI table
    ... ocean_buoys_nonpti = DataFrame("ocean_buoys_nonpti")
    >>> # Check DataFrame columns and let's peek at the data
    ... ocean_buoys_nonpti.columns
    ['buoyid', 'timecode', 'temperature', 'salinity']
    >>> ocean_buoys_nonpti.head()
                                buoyid  temperature  salinity
    timecode
    2014-01-06 08:09:59.999999       0         99.0        55
    2014-01-06 08:10:00.000000       0         10.0        55
    2014-01-06 09:01:25.122200       1         70.0        55
    2014-01-06 09:01:25.122200       1         77.0        55
    2014-01-06 09:02:25.122200       1         71.0        55
    2014-01-06 09:03:25.122200       1         72.0        55
    2014-01-06 09:02:25.122200       1         78.0        55
    2014-01-06 08:10:00.000000       0        100.0        55
    2014-01-06 08:08:59.999999       0          NaN        55
    2014-01-06 08:00:00.000000       0         10.0        55
 
    >>> ocean_buoys_nonpti_grpby1 = ocean_buoys_nonpti.groupby_time(timebucket_duration="10minutes",
    ...                                                             value_expression="buoyid",
    ...                                                             timecode_column="timecode", fill="NULLS")
    >>> ocean_buoys_nonpti_grpby1.mode().sort(["TIMECODE_RANGE", "buoyid"])
                                          TIMECODE_RANGE  GROUP BY TIME(MINUTES(10))  buoyid  mode_temperature  mode_salinity
    0  ('2014-01-06 08:00:00.000000+00:00', '2014-01-...                     2314993       0                99             55
    1  ('2014-01-06 08:00:00.000000+00:00', '2014-01-...                     2314993       0                10             55
    2  ('2014-01-06 08:10:00.000000+00:00', '2014-01-...                     2314994       0                10             55
    3  ('2014-01-06 08:10:00.000000+00:00', '2014-01-...                     2314994       0               100             55
    4  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                70             55
    5  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                71             55
    6  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                72             55
    7  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                77             55
    8  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                78             55
    9  ('2014-01-06 09:00:00.000000+00:00', '2014-01-...                     2314999       1                79             55