Skip to Content

Python Functions

These are example Python functions you can use as a starting point for developing your own code. Please be aware that these functions are not rigorously tested, so they should NOT be used for production purposes without further validation. They are provided purely as examples with no representation or warranty of any kind.

If there is a function you’d like to see an example of, please email us.

Data

FunctionDescription
BASIC_CHARTGenerates a matplotlib chart from 2D numeric data and returns a PNG image as a base64 string.
EXCHANGE_RATERetrieves the exchange rate from a base currency to a target currency using a public API.
INTERNET_CSVFetches a CSV file from the internet (with CORS proxy) and returns its contents as a 2D list.
ONEDRIVE_CSVRetrieves a CSV file from the user’s Microsoft OneDrive App Folder using the Microsoft Graph API and a global variable graphToken for authentication. Returns the CSV contents as a 2D list, suitable for use in Excel.
SALESFORCE_APISRetrieves available Salesforce REST APIs and returns them as a 2D list.
WORDCLOUDGenerates a word cloud image from provided text data and returns a PNG image as a base64 string.

Engineering

Fluids

FunctionDescription
AIRMASSCalculate the mass of air per square meter in the atmosphere along a given angle using a density profile.
ARCHIMEDESCalculate the Archimedes number (Ar) for a fluid and particle.
ATMOSPHERE_1976Calculate standard atmospheric properties at a given altitude using the US Standard Atmosphere 1976 model.
ATMOSPHERE_NRLMSISE00Compute temperature, density, and pressure using the NRLMSISE-00 atmospheric model.
BEJANCompute the Bejan number (length-based or permeability-based) using fluids.core library.
BOILINGCalculate the Boiling number (Bg), a dimensionless number for boiling heat transfer.
BONDCalculate the Bond number (Bo), a dimensionless number comparing gravitational and surface tension forces.
CAPILLARYCalculate the Capillary number (Ca) for a fluid system.
CAVITATIONCalculate the Cavitation number (Ca) for a flowing fluid.
CONFINEMENTCalculate the Confinement number (Co) for two-phase flow in a channel.
DEANCalculate the Dean number (De) for flow in a curved pipe or channel.
DRAGCalculate the drag coefficient (dimensionless) for an object in a fluid.
ECKERTCalculate the Eckert number (Ec) for a given velocity, heat capacity, and temperature difference.
EULERCalculate the Euler number (Eu) for a fluid flow.
FOURIER_HEATCalculate the Fourier number for heat transfer.
FOURIER_MASSCalculate the Fourier number for mass transfer (Fo).
FROUDECalculate the Froude number (Fr) for a given velocity, length, and gravity.

Photovoltaics

FunctionDescription
CALCPARAMS_CECCalculate five CEC model parameters for the single diode equation at given irradiance and cell temperature.
CLEARSKYCalculate clear sky GHI, DNI, and DHI for a location and time using PVLib.
I_FROM_VCalculate the device current at a given device voltage for a PV cell/module using the single diode model.
IRRADIANCECalculate the plane of array irradiance components on a tilted surface using PVLib.
PVWATTS_DCCalculate the DC power output of a PV module using the PVWatts DC model.
SOLARPOSITIONCalculate solar azimuth, elevation, and apparent zenith for given times and location.
FunctionDescription
PSYCHROMETRICSPerform core psychrometric calculations: wet bulb, dew point, humidity ratio, enthalpy.
STRUCTURAL_FEAPerforms 3D finite element analysis using the Pynite package and returns support reactions. This function is provided as an example only without any representation or warranty of correctness. DO NOT rely on for production use without your own testing and validation.

Financial

FunctionDescription
BLACK_SCHOLESCalculate the Black-Scholes price for a European call or put option.
GIFI_BALAssign GIFI asset codes to balance sheet row labels using an AI model.
PORTFOLIO_REBALANCERTax-efficient rebalancing of assets across Taxable, Roth, and Traditional accounts.
STOCK_PRICERetrieves the latest daily closing price for a given stock symbol using the Alpha Vantage API.

Math

Integration

FunctionDescription
DBLQUADCompute the double integral of a function over a two-dimensional region.
QUADNumerically integrate a function defined by a table of x, y values over [a, b] using adaptive quadrature.
SOLVE_IVPSolve an initial value problem for a system of ODEs of the form dy/dt = A @ y.
TRAPEZOIDIntegrate sampled data using the composite trapezoidal rule.

Interpolation

FunctionDescription
BPOLYConstruct a piecewise polynomial in the Bernstein basis and evaluate it at specified points.
CUBIC_HERMITE_SPLINEPiecewise cubic interpolation matching values and first derivatives at each point.
CUBIC_SPLINEPerform cubic spline interpolation for 1D data.
GRIDDATAInterpolate unstructured N-D data using scipy.interpolate.griddata.
PPOLYConstruct and evaluate a piecewise polynomial in the power basis.

Linear Algebra

FunctionDescription
CHOLESKYCompute the Cholesky decomposition of a Hermitian, positive-definite matrix.
EXPMCompute the matrix exponential of a square matrix.
LSTSQCompute the least-squares solution to Ax = B using scipy.linalg.lstsq.
PINVCompute the Moore-Penrose pseudoinverse of a matrix using SVD.
QRCompute the QR decomposition of a matrix and return either Q or R.
SVDCompute the Singular Value Decomposition (SVD) of a matrix.

Optimization

FunctionDescription
BASIN_HOPPINGFinds the global minimum of a single-variable function using the basinhopping algorithm.
HESSIAN_MATRIXComputes the HESSIAN_MATRIX matrix (second derivatives) of a scalar function with respect to its variables.
JACOBIAN_MATRIXCalculate the JACOBIAN_MATRIX matrix of a mathematical expression with respect to specified variables.
LEAST_SQUARESSolve a nonlinear least-squares problem by fitting a user-defined model to data.
LINEAR_ASSIGNMENTSolves the linear assignment problem (Hungarian algorithm) for a given cost matrix.
LINEAR_PROGSolves a linear programming problem using scipy.optimize.linprog.
MINIMIZEMinimizes a multivariate function using scipy.optimize.minimize.
MINIMIZE_SCALARMinimizes a scalar function using scipy.optimize.minimize_scalar.
QUADRATIC_ASSIGNMENTSolves the quadratic assignment problem (QAP) for given flow and distance matrices.
ROOTSolves a square system of nonlinear equations using SciPy’s root-finding capabilities.
SENSITIVITY_MATRIXComputes the sensitivity matrix of a model output with respect to parameters using CasADi.

Statistical

Association Correlation Tests

FunctionDescription
BARNARD_EXACTPerform Barnard’s exact test on a 2x2 contingency table.
BOSCHLOO_EXACTPerform Boschloo’s exact test on a 2x2 contingency table.
CHI2_CONTINGENCYPerform the chi-square test of independence for variables in a contingency table.
FISHER_EXACTPerform Fisher’s exact test on a contingency table.
KENDALLTAUCalculate Kendall’s tau, a correlation measure for ordinal data.
PAGE_TREND_TESTPerform Page’s L trend test for monotonic trends across treatments.
PEARSONRCalculate the Pearson correlation coefficient and p-value for two datasets.
POINTBISERIALRCalculate a point biserial correlation coefficient and its p-value.
SIEGELSLOPESCompute the Siegel repeated medians estimator for robust linear regression.
SOMERSDCalculate Somers’ D, an asymmetric measure of ordinal association between two variables.
SPEARMANRCalculate a Spearman correlation coefficient with associated p-value.
THEILSLOPESCompute the Theil-Sen estimator for a set of points (robust linear regression).
WEIGHTEDTAUCompute a weighted version of Kendall’s tau correlation coefficient.

Clustering

FunctionDescription
DENDROGRAMPerforms hierarchical (agglomerative) clustering on numeric data and returns a dendrogram as a base64-encoded PNG image or an error message.

Continuous Distributions

FunctionDescription
BETAGeneralized Beta distribution function supporting multiple methods.
CAUCHYCauchy distribution function supporting multiple methods.
CHISQChi-squared distribution function supporting multiple methods.
EXPONExponential distribution function supporting multiple methods.
F_DISTUnified interface to the main methods of the F-distribution, including PDF, CDF, inverse CDF, survival function, and distribution statistics.
LAPLACELaplace distribution function supporting multiple methods.
LOGNORMGeneralized lognormal distribution function supporting multiple methods.
NORMNormal (Gaussian) distribution function supporting multiple methods.
PARETOGeneralized Pareto distribution function supporting multiple methods.
T_DISTStudent’s t distribution function supporting multiple methods.
UNIFORMUniform distribution function supporting multiple methods.
WEIBULL_MINWeibull minimum distribution function supporting multiple methods.

Discrete Distributions

FunctionDescription
BERNOULLICalculates properties of a Bernoulli discrete random variable.
BETABINOMCompute Beta-binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
BETANBINOMCompute Beta-negative-binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
BINOMCompute Binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
BOLTZMANNCompute Boltzmann distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
DLAPLACECompute Discrete Laplace distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
GEOMCompute Geometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
HYPERGEOMCompute Hypergeometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
LOGSERCompute Log-Series distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
NBINOMCompute Negative Binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
NHYPERGEOMCompute Negative Hypergeometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
PLANCKCompute Planck distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
POISSON_DISTCompute Poisson distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
RANDINTCompute Uniform discrete distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
SKELLAMCompute Skellam distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
YULESIMONCompute Yule-Simon distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
ZIPFCompute Zipf distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
ZIPFIANCompute Zipfian distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.

Frequency Statistics

FunctionDescription
BINNED_STATISTICComputes a binned statistic (mean, sum, median, etc.) for the input data.
BINNED_STATISTIC_2DComputes a bidimensional binned statistic (mean, sum, median, etc.) for the input data.
CUMFREQReturns the cumulative frequency histogram for the input data.
PERCENTILEOFSCOREComputes the percentile rank of a score relative to the input data.
RELFREQReturns the relative frequency histogram for the input data.
SCOREATPERCENTILECalculates the score at the given percentile of the input data.

Independent Tests

FunctionDescription
ALEXANDERGOVERNPerforms the Alexander-Govern test for equality of means across multiple independent samples with possible heterogeneity of variance.
ANDERSON_KSAMPPerforms the k-sample Anderson-Darling test to determine if samples are drawn from the same population.
ANSARIPerforms the Ansari-Bradley test for equal scale parameters (non-parametric).
BRUNNERMUNZELComputes the Brunner-Munzel nonparametric test for two independent samples.
BWS_TESTPerforms the Baumgartner-Weiss-Schindler test on two independent samples.
CRAMERVONMISES_2SAMPPerforms the two-sample Cramér-von Mises test for goodness of fit between two independent samples.
DUNNETTPerforms Dunnett’s test for multiple comparisons of means against a control group.
EPPS_SINGLETON_2SAMPComputes the Epps-Singleton test statistic and p-value for two samples.
F_ONEWAYPerforms a one-way ANOVA test for two or more independent samples.
FLIGNERPerforms the Fligner-Killeen test for equality of variances across multiple samples.
FRIEDMANCHISQUAREComputes the Friedman test for repeated samples.
KRUSKALComputes the Kruskal-Wallis H-test for independent samples.
KS_2SAMPPerforms the two-sample Kolmogorov-Smirnov test for goodness of fit.
KSTESTPerforms the Kolmogorov-Smirnov test for goodness of fit between two samples or a sample and a reference distribution.
LEVENEPerforms the Levene test for equality of variances across multiple samples.
MANNWHITNEYUPerforms the Mann-Whitney U rank test on two independent samples.
MEDIAN_TESTPerforms Mood’s median test to determine if two or more independent samples come from populations with the same median.
MOODPerforms Mood’s two-sample test for scale parameters (non-parametric).
POISSON_MEANS_TESTPerforms the Poisson means test (E-test) to compare the means of two Poisson distributions.
RANKSUMSComputes the Wilcoxon rank-sum statistic and p-value for two independent samples.
TTEST_INDPerforms the independent two-sample t-test for the means of two groups.
TTEST_IND_FROM_STATSPerforms a t-test for means of two independent samples using summary statistics.
TUKEY_HSDPerforms Tukey’s HSD test for equality of means over multiple treatments.

Miscellaneous

FunctionDescription
VAL_DISCRETESelect a value from a list based on a discrete probability distribution.

Multivariate Distributions

FunctionDescription
DIRICHLETComputes the PDF, log-PDF, mean, variance, covariance, entropy, or draws random samples from a Dirichlet distribution.
DIRICHLET_MULTINOMIALComputes the probability mass function, log probability mass function, mean, variance, or covariance of the Dirichlet multinomial distribution.
MATRIX_NORMALComputes the PDF, log-PDF, or draws random samples from a matrix normal distribution.
MULTINOMIALComputes the probability mass function, log-PMF, entropy, covariance, or draws random samples from a multinomial distribution.
MULTIVARIATE_HYPERGEOMComputes probability mass function, log-PMF, mean, variance, covariance, or draws random samples from a multivariate hypergeometric distribution.
MULTIVARIATE_NORMALComputes the PDF, CDF, log-PDF, log-CDF, entropy, or draws random samples from a multivariate normal distribution.
MULTIVARIATE_TComputes the PDF, CDF, or draws random samples from a multivariate t-distribution.
ORTHO_GROUPDraws random samples of orthogonal matrices from the O(N) Haar distribution.
RANDOM_CORRELATIONGenerates a random correlation matrix with specified eigenvalues.
SPECIAL_ORTHO_GROUPDraws random samples from the special orthogonal group SO(N), returning orthogonal matrices with determinant +1.
UNIFORM_DIRECTIONDraws random unit vectors uniformly distributed on the surface of a hypersphere in the specified dimension.
UNITARY_GROUPGenerates a random unitary matrix of dimension N.
VONMISES_FISHERComputes the PDF, log-PDF, entropy, or draws random samples from a von Mises-Fisher distribution on the unit hypersphere.
WISHARTComputes the PDF, log-PDF, or draws random samples from a Wishart distribution.

One And Paired Tests

FunctionDescription
BINOMTESTPerform a binomial test for the probability of success in a Bernoulli experiment.
JARQUE_BERAPerform the Jarque-Bera goodness of fit test for normality.
KURTOSISTESTTest whether the kurtosis of a sample is different from that of a normal distribution.
NORMALTESTTest whether a sample differs from a normal distribution (omnibus test).
QUANTILE_TESTPerform a quantile test and compute a confidence interval of the quantile.
SHAPIROPerform the Shapiro-Wilk test for normality.
SKEWTESTTest whether the skewness of a sample is different from that of a normal distribution.
TTEST_1SAMPPerform a one-sample t-test for the mean of a group of scores.

Summary Statistics

FunctionDescription
DESCRIBECompute descriptive statistics of a dataset: nobs, min, max, mean, variance, skewness, kurtosis.
EXPECTILECalculates the expectile of a dataset.
GMEANCompute the geometric mean of the input data, flattening the input and ignoring non-numeric values.
HMEANCalculates the harmonic mean of the input data.
KURTOSISComputes the kurtosis (Fisher or Pearson) of a dataset.
MODEReturns the modal (most common) value in the passed array. Flattens the input, ignores non-numeric values, and always returns a single mode (the smallest if multiple). If no mode is found, returns “No mode found”.
MOMENTCalculates the nth moment about the mean for a sample.
PMEANComputes the power mean (generalized mean) of the input data for a given power p.
SKEWNESSCalculate the skewness of a dataset.

Text

FunctionDescription
AI_ASKGenerate a text response using an AI model based on a prompt and optional tabular data.
AI_CHOICEUses AI to select the most appropriate choice from a list of options based on the given context.
AI_EXTRACTUses an AI model to extract specific types of information from unstructured text.
AI_FILLFills missing or incomplete data in a target range by learning patterns from an example range using a large language model.
AI_FORMATUses an AI model to format text according to a specific structure or pattern.
AI_LISTGenerate a list of items using an AI model based on a prompt and optional context values.
AI_TABLEUses an AI model to generate a structured table (2D list) based on a prompt, with optional header and source data.
JINA_READERReturns web page content in markdown format using Jina. Useful as a starting point for extraction, summarization, etc.
TEXT_DISTANCECalculate text similarity scores between lookup_value(s) and lookup_array items using the specified algorithm.
VADER_SENTIMENTAnalyze sentiment of text using VADER.
Last updated on