Math functions#

On top of the functions listed below, measures can also be combined with mathematical operators.

  • The classic +, - and * operators:

    >>> df = pd.DataFrame(
    ...     columns=["City", "A", "B", "C", "D"],
    ...     data=[
    ...         ("Berlin", 15.0, 10.0, 10.1, 1.0),
    ...         ("London", 24.0, 16.0, 20.5, 3.14),
    ...         ("New York", -27.0, 15.0, 30.7, 10.0),
    ...         ("Paris", 0.0, 0.0, 0.0, 0.0),
    ...     ],
    ... )
    >>> table = session.read_pandas(df, keys=["City"], table_name="Math")
    >>> cube = session.create_cube(table)
    >>> l, m = cube.levels, cube.measures
    >>> m["Sum"] = m["A.SUM"] + m["B.SUM"]
    >>> m["Subtract"] = m["A.SUM"] - m["B.SUM"]
    >>> m["Multiply"] = m["A.SUM"] * m["B.SUM"]
    >>> cube.query(
    ...     m["A.SUM"],
    ...     m["B.SUM"],
    ...     m["Sum"],
    ...     m["Subtract"],
    ...     m["Multiply"],
    ...     levels=[l["City"]],
    ... )
               A.SUM  B.SUM     Sum Subtract Multiply
    City
    Berlin     15.00  10.00   25.00     5.00   150.00
    London     24.00  16.00   40.00     8.00   384.00
    New York  -27.00  15.00  -12.00   -42.00  -405.00
    Paris        .00    .00     .00      .00      .00
    
  • The float division / and integer division //:

    >>> m["Float division"] = m["A.SUM"] / m["B.SUM"]
    >>> m["Int division"] = m["A.SUM"] // m["B.SUM"]
    >>> cube.query(
    ...     m["A.SUM"],
    ...     m["B.SUM"],
    ...     m["Float division"],
    ...     m["Int division"],
    ...     levels=[l["City"]],
    ... )
               A.SUM  B.SUM Float division Int division
    City
    Berlin     15.00  10.00           1.50         1.00
    London     24.00  16.00           1.50         1.00
    New York  -27.00  15.00          -1.80        -2.00
    Paris        .00    .00            NaN          NaN
    
  • The exponentiation **:

    >>> m["a²"] = m["A.SUM"] ** 2
    >>> cube.query(m["A.SUM"], m["a²"], levels=[l["City"]])
               A.SUM      a²
    City
    Berlin     15.00  225.00
    London     24.00  576.00
    New York  -27.00  729.00
    Paris        .00     .00
    
  • The modulo %:

    >>> m["Modulo"] = m["A.SUM"] % m["B.SUM"]
    >>> cube.query(m["A.SUM"], m["B.SUM"], m["Modulo"], levels=[l["City"]])
               A.SUM  B.SUM Modulo
    City
    Berlin     15.00  10.00   5.00
    London     24.00  16.00   8.00
    New York  -27.00  15.00   3.00
    Paris        .00    .00    NaN
    

abs

Return a measure equal to the absolute value of the passed measure.

ceil

Return a measure equal to the smallest integer that is >= to the passed measure.

cos

Return a measure equal to the cosine of the passed measure in radians.

erf

Return the error function of the input measure.

erfc

Return the complementary error function of the input measure.

exp

Return a measure equal to the exponential value of the passed measure.

floor

Return a measure equal to the largest integer <= to the passed measure.

isnan

Return a measure equal to True when the passed measure is NaN and to False otherwise.

log

Return a measure equal to the natural logarithm (base e) of the passed measure.

log10

Return a measure equal to the base 10 logarithm of the passed measure.

max

Return a measure equal to the maximum of the passed arguments.

min

Return a measure equal to the minimum of the passed arguments.

round

Return a measure equal to the closest integer to the passed measure.

sin

Return a measure equal to the sine of the passed measure in radians.

sqrt

Return a measure equal to the square root of the passed measure.

tan

Return a measure equal to the tangent of the passed measure in radians.