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): Returnsif_truewhereconditionis true,if_falseotherwise. Works element-wise on arrays.coalesce(*values): First non-null/non-empty value.isna(value):Trueif the value is null or empty. Works element-wise on arrays.notna(value):Trueif the value is not null or empty. Works element-wise on arrays.fillna(values, fill): Replaces null or empty values withfill.
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 ofvalue.clip(value, lo: float, hi: float): Clamp value to the range [lo,hi].
Comparison / Boolean
eq(a, b):Trueifa == b. Works element-wise on arrays.ne(a, b):Trueifa != b. Works element-wise on arrays.gt(a, b):Trueifa > b. Works element-wise on arrays.gte(a, b):Trueifa >= b. Works element-wise on arrays.lt(a, b):Trueifa < b. Works element-wise on arrays.lte(a, b):Trueifa <= b. Works element-wise on arrays.between(value, lo, hi):Trueiflo <= value <= hi. Works element-wise on arrays.contains(text: str, substring: str):Trueiftextcontainssubstring. Works element-wise on arrays.startswith(text: str, prefix: str):Trueiftextstarts withprefix. Works element-wise on arrays.endswith(text: str, suffix: str):Trueiftextends withsuffix. 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 ofoldwithnew. Works element-wise on arrays.split(text: str, sep: str): Splittextbysepand return a list.join(values, sep: str): Join values into a string separated bysep.len(value): Length of a string or number of elements in an array.
Date / Time
parse_date(text: str, fmt: str | None = None): Parsetextinto a datetime. IffmtisNone, the format is inferred.format_date(dt, fmt: str): Format a datetime as a string usingfmt.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, where0is Monday and6is Sunday.
Ranking / Analytic
rank(values, method: str = "average"): Rank of each value.methodcan 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 valueperiodspositions earlier.cumsum(values): Cumulative sum.pct_change(values, periods: int = 1): Percentage change fromperiodspositions earlier.
Statistical / Data Cleanup
percentile(values, p: float): Thep-th percentile, from 0 to 100.quantile(values, q: float): Theq-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 ofstep.
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): Solvea @ 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.