Programming with Python in the Calculator
The Calculator allows you to write simple Python expressions and scripts to compute new variables. You do not need advanced Python knowledge: most use cases rely on basic assignments, conditions, and standard numerical functions.
Basic assignments
Assigning numerical or categorical values
Copying an auxiliary variable
Simple transformations
Conditions and logical expressions
Conditional statements allow you to apply different computations depending on variable values. They are commonly used to mask values, apply thresholds, or define piecewise calculations.
Simple if statement
Use an if statement to apply an operation only when a condition is satisfied.
The general Python syntax is:
If the condition evaluates to True, the indented statements are executed. Otherwise, they are skipped.
Comparison operators
Comparison operators are used to build conditions. They return a Boolean value (True or False).
Logical operators
Logical operators allow you to combine multiple conditions.
If–else statement
Use an if–else statement to define alternative computations depending on whether a condition is met.
The general syntax is:
Each block may contain any number of Python statements, including assignments, function calls, or nested conditions.
Character strings
Test whether a string (for example "abc") is contained in another string:
Compare two character strings (alphabetical order):
Length of a character string:
Access the third character of a string:
Note: String indexing starts at 0.
Using dataset and variable metadata
The read-only info dictionary provides access to dataset and variable metadata. It allows you to write generic scripts that automatically adapt to the current context.
Example: inspect the current dataset and selection.
ds = info["dataset"]
print(f'{ds["dir_name"]} / {ds["file_name"]} — table: {ds["table_name"]}')
print("Selection:", ds.get("sel_name") or "(none)")
print("Samples:", ds["sample_count"], "— Dimension:", ds["dimension"])
Example: build a list of numeric-compatible variables.
numeric_aliases = []
for alias, meta in info["vars"].items():
if "catalog" not in meta:
numeric_aliases.append(alias)
print("Numeric aliases:", numeric_aliases)
Macro variables (requires Macro Behavior = “Access macro indices in numpy array”):
meta = info["vars"].get("m5", {})
indices = meta.get("indices")
if indices is not None:
# list of ints, or dict int→float/string depending on macro type
print("Macro indices for m5:", indices)
Numerical functions (NumPy)
NumPy is the core numerical library used by the Calculator. It is automatically imported as np when the Calculator is initialized. All NumPy functions must therefore be called using the np. prefix.
ceil(x) # Returns the ceiling of x as a float, the smallest integer value greater than or equal to x.
fabs(x) # Returns the absolute value of x.
floor(x) # Returns the floor of x as a float, the largest integer value less than or equal to x.
isinf(x) # Checks if the float x is positive or negative infinity.
isnan(x) # Checks if the float x is NaN (not a number). For more information on NaNs, see the IEEE 754 standards.
exp(x) # Returns e**x.
log(x) # Returns the natural logarithm of x to base e.
log10(x) # Returns the bas 10 logarithm of x. This is usually more accurate than log(x,10).
power(x,y) # Returns x raised to the power y.
sqrt(x) # Returns the square root of x.
arccos(x) # Returns the arc cosine of x in radians.
arcsin(x) # Returns the arc sine of x in radians.
cos(x) # Returns the coseine of x in radians.
hypot(x) # Returns the Euclidian norm, sqrt(x*x+y*y). This is the length of the vector from the origin point (x,y).
sin(x) # Returns the sine of x in radians.
tan(x) # Returns the tangent of x in radians.
degrees(x) # Converts angle x from radians to degrees.
radians(x) # Converts angles x from degrees to radians.
pi # the mathematical constant 3.14.1592..., to available precision.
e # The mathematical constant e=2.718281..., to available precision.
nan # The "not a number" constant value. To only be used for a variable initialization.
inf # The infinite value.
- inf # The -infinite value.
Random number generation (NumPy)
The following NumPy functions can be used to generate random values and distributions. For detailed documentation, see NumPy random functions.
Random number generation functions are available through the np.random module.
beta(a, b[, size]) # Draw samples from a Beta distribution.
binomial(n, p[, size]) # Draw samples from a binomial distribution.
chisquare(df[, size]) # Draw samples from a chi-square distribution.
exponential([scale, size]) # Draw samples from an exponential distribution.
f(dfnum, dfden[, size]) # Draw samples from an F distribution.
gamma(shape[, scale, size]) # Draw samples from a Gamma distribution.
geometric(p[, size]) # Draw samples from the geometric distribution.
gumbel([loc, scale, size]) # Draw samples from a Gumbel distribution.
laplace([loc, scale, size]) # Draw samples from the Laplace or double exponential distribution with specified location (or mean) and scale (decay).
logistic([loc, scale, size]) # Draw samples from a logistic distribution.
lognormal([mean, sigma, size]) # Draw samples from a log-normal distribution.
logseries(p[, size]) # Draw samples from a logarithmic series distribution.
multinomial(n, pvals[, size]) # Draw samples from a multinomial distribution.
multivariate_normal(mean, cov[, size, ...]) # Draw random samples from a multivariate normal distribution.
negative_binomial(n, p[, size]) # Draw samples from a negative binomial distribution.
normal([loc, scale, size]) # Draw random samples from a normal (Gaussian) distribution.
pareto(a[, size]) # Draw samples from a Pareto II or Lomax distribution with specified shape.
poisson([lam, size]) # Draw samples from a Poisson distribution.
power(a[, size]) # Draws samples in [0, 1] from a power distribution with positive exponent a - 1.
rayleigh([scale, size]) # Draw samples from a Rayleigh distribution.
standard_cauchy([size]) # Draw samples from a standard Cauchy distribution with mode = 0.
standard_exponential([size]) # Draw samples from the standard exponential distribution.
standard_gamma(shape[, size]) # Draw samples from a standard Gamma distribution.
standard_normal([size]) # Draw samples from a standard Normal distribution (mean=0, stdev=1).
standard_t(df[, size]) # Draw samples from a standard Student's t distribution with df degrees of freedom.
triangular(left, mode, right[, size]) # Draw samples from the triangular distribution over the interval [left, right].
uniform([low, high, size]) # Draw samples from a uniform distribution.
vonmises(mu, kappa[, size]) # Draw samples from a von Mises distribution.
wald(mean, scale[, size]) # Draw samples from a Wald, or inverse Gaussian, distribution.
weibull(a[, size]) # Draw samples from a Weibull distribution.
zipf(a[, size]) # Draw samples from a Zipf distribution.
Available Python packages
The Python distribution embedded in Isatis.neo includes a set of commonly used Python packages that are available by default when writing Python scripts (for example in the Calculator, batch files, or the Python Script Launcher). The list below is not exhaustive.
- NumPy – numerical arrays and mathematical operations (numpy.org).
- Pandas – DataFrame-based data manipulation (pandas.pydata.org).
- SciPy – numerical integration, interpolation, linear algebra, and statistics (scipy.org).
- Matplotlib – plotting and visualization (matplotlib.org).
- Seaborn – statistical data visualization based on Matplotlib (seaborn.pydata.org).
- scikit-learn – machine learning and data analysis tools (scikit-learn.org).
- openpyxl – reading and writing Excel files (pypi.org).
- PySide2 – Qt bindings for Python, used for graphical interfaces (pypi.org).
Note: Additional Python packages can be installed on a per-project basis. For more information, see Python preferences.
