Skip to content

Analysis Tools API Reference

Formulas and Scripts share these helpers under the mc namespace. In Scripts, the analysis helpers are also available under mc.analysis (and mirrored directly on mc). Function names below omit the mc. prefix.

Most functions accept a scalar, Python list, NumPy array, or 2D array. Functions that return arrays return NumPy arrays.

Constants

  • e: Euler's number.
  • pi: The constant π.

Aggregation

  • sum(values): Sum of all values.
  • mean(values): Arithmetic mean.
  • median(values): Median.
  • min(values): Minimum value.
  • max(values): Maximum value.
  • count(values): Total number of values.
  • count_nonempty(values): Number of non-empty values.
  • count_empty(values): Number of empty values.
  • nunique(values): Number of unique values.
  • std(values): Standard deviation.
  • var(values): Variance.

Conditional / Null Handling

  • ifelse(condition, if_true, if_false): Returns if_true where condition is true, if_false otherwise. Works element-wise on arrays.
  • coalesce(*values): First non-null/non-empty value.
  • isna(value): True if the value is null or empty. Works element-wise on arrays.
  • notna(value): True if the value is not null or empty. Works element-wise on arrays.
  • fillna(values, fill): Replaces null or empty values with fill.

Math

  • abs(value): Absolute value. Works element-wise on arrays.
  • round(value, decimals: int = 0): Round to the given number of decimal places.
  • floor(value): Round down to the nearest integer.
  • ceil(value): Round up to the nearest integer.
  • sqrt(value): Square root.
  • log(value, base: float = e): Logarithm with the given base.
  • exp(value): Euler's number raised to the power of value.
  • clip(value, lo: float, hi: float): Clamp value to the range [lo, hi].

Comparison / Boolean

  • eq(a, b): True if a == b. Works element-wise on arrays.
  • ne(a, b): True if a != b. Works element-wise on arrays.
  • gt(a, b): True if a > b. Works element-wise on arrays.
  • gte(a, b): True if a >= b. Works element-wise on arrays.
  • lt(a, b): True if a < b. Works element-wise on arrays.
  • lte(a, b): True if a <= b. Works element-wise on arrays.
  • between(value, lo, hi): True if lo <= value <= hi. Works element-wise on arrays.
  • contains(text: str, substring: str): True if text contains substring. Works element-wise on arrays.
  • startswith(text: str, prefix: str): True if text starts with prefix. Works element-wise on arrays.
  • endswith(text: str, suffix: str): True if text ends with suffix. Works element-wise on arrays.

String

  • lower(text: str): Convert to lowercase. Works element-wise on arrays.
  • upper(text: str): Convert to uppercase. Works element-wise on arrays.
  • strip(text: str): Remove leading and trailing whitespace. Works element-wise on arrays.
  • replace(text: str, old: str, new: str): Replace all occurrences of old with new. Works element-wise on arrays.
  • split(text: str, sep: str): Split text by sep and return a list.
  • join(values, sep: str): Join values into a string separated by sep.
  • len(value): Length of a string or number of elements in an array.

Date / Time

  • parse_date(text: str, fmt: str | None = None): Parse text into a datetime. If fmt is None, the format is inferred.
  • format_date(dt, fmt: str): Format a datetime as a string using fmt.
  • year(dt): Year component.
  • month(dt): Month component.
  • day(dt): Day component.
  • hour(dt): Hour component.
  • minute(dt): Minute component.
  • weekday(dt): Day of week, where 0 is Monday and 6 is Sunday.

Ranking / Analytic

  • rank(values, method: str = "average"): Rank of each value. method can be "average", "min", "max", "dense", or "ordinal".
  • sort(values, ascending: bool = True): Sort values.
  • unique(values): Unique values in order of first appearance.
  • diff(values, periods: int = 1): Difference from the value periods positions earlier.
  • cumsum(values): Cumulative sum.
  • pct_change(values, periods: int = 1): Percentage change from periods positions earlier.

Statistical / Data Cleanup

  • percentile(values, p: float): The p-th percentile, from 0 to 100.
  • quantile(values, q: float): The q-th quantile, from 0 to 1.
  • zscore(values): Z-score.
  • normalize(values, lo: float = 0, hi: float = 1): Normalize values to the range [lo, hi].
  • round_to(value, step: float): Round to the nearest multiple of step.

Trigonometric

All operate element-wise on scalars, lists, and matrices (angles in radians unless noted).

  • sin(value): Sine.
  • cos(value): Cosine.
  • tan(value): Tangent.
  • asin(value): Arcsine.
  • acos(value): Arccosine.
  • atan(value): Arctangent.
  • atan2(y, x): Two-argument arctangent.
  • degrees(value): Convert radians to degrees.
  • radians(value): Convert degrees to radians.

Hyperbolic

Element-wise on scalars, lists, and matrices.

  • sinh(value): Hyperbolic sine.
  • cosh(value): Hyperbolic cosine.
  • tanh(value): Hyperbolic tangent.
  • asinh(value): Inverse hyperbolic sine.
  • acosh(value): Inverse hyperbolic cosine.
  • atanh(value): Inverse hyperbolic tangent.

Matrix / Linear Algebra

Accept 1D/2D lists or arrays.

  • matmul(a, b): Matrix (or matrix-vector) product.
  • dot(a, b): Dot product.
  • inv(matrix): Inverse of a square matrix.
  • pinv(matrix): Pseudoinverse.
  • det(matrix): Determinant.
  • eig(matrix): Eigenvalues and eigenvectors. Returns (values, vectors).
  • eigh(matrix): For Hermitian/symmetric matrices. Returns (values, vectors).
  • solve(a, b): Solve a @ x = b.
  • transpose(matrix): Transpose.
  • trace(matrix): Sum of diagonal elements.

Stats

  • corrcoef(x, y=None): Correlation coefficient matrix (or between two series).
  • cov(x, y=None): Covariance matrix (or between two series).

Use these for correlation and covariance estimates on vectors or matrices. For specialized estimators not listed here, import from NumPy or SciPy directly.