MaterialTech Labs
Blog � Generative Design

Python for engineers: from Excel to automation

Repetitive calculations, CFD simulations you need to post-process, spreadsheets that no longer scale. Python gives you reproducibility, traceability and a scientific ecosystem that transforms your workflow.

Jul 2026 � 10 min read � Generative Design

Why Python and not Excel

Excel has been the engineer's ubiquitous tool for three decades. But it has fundamental limitations that become painful as work scales: lack of traceability (you do not know which cells someone modified or when), inability to version (binary files cannot be diffed), silent errors from broken formulas when inserting rows, and a limit of approximately 1M rows that is quickly reached with simulation data.

Python solves all of this. It is plain text versionable with Git, every result is reproducible by running the script, the scientific libraries (NumPy, SciPy, Pandas, Matplotlib) have decades of development and validation, and the same tool reads a 50-line CSV or a 50-million-point dataset from a CFD simulation. The learning cost is recouped within weeks: a script that saves 2 hours per week of manual calculation pays for itself in the first month.

Setting up your environment in 10 minutes

Installing Python correctly avoids future headaches. The recommendation for engineers: Miniforge (lightweight conda-forge distribution) or Anaconda, which includes the main scientific libraries precompiled and avoids Windows dependency conflicts that are the main barrier to entry.

Recommended installation:

  1. Download Miniforge from github.com/conda-forge/miniforge.
  2. Create an engineering-specific environment: conda create -n engineering python=3.12 numpy scipy pandas matplotlib jupyterlab
  3. Activate the environment: conda activate engineering
  4. Editor: VS Code with the Python extension. Alternative for exploratory analysis: JupyterLab, which allows running code cells interactively and viewing integrated plots �ideal for simulation post-processing where you iterate on visualizations.

A key detail: using isolated conda environments per project avoids "dependency hell" where an updated library breaks old scripts. Each project has its own environment with specific versions, documented in an environment.yml file that any teammate can replicate with a single command.

NumPy: vectorized computing without loops

The fundamental operation of computational engineering is working with arrays of numbers: mesh node coordinates, pressure time series, 3D velocity fields. NumPy provides the N-dimensional array (ndarray) and vectorized operations that run at compiled C speed, not interpreted Python speed.

The performance difference is brutal: adding two arrays of 1 million elements takes approximately 1 ms with vectorized NumPy versus approximately 200 ms with a pure Python for loop. This is not micro-optimization: when you are post-processing a CFD field of 5 million cells, the difference between 5 seconds and 15 minutes determines whether you iterate or give up.

import numpy as np

# Create engineering arrays
x = np.linspace(0, 10, 100)         # 100 equidistant points
stress = 250 + 50 * np.sin(x)       # Sinusoidal stress, MPa

# Vectorized operations
von_mises = np.sqrt(stress**2 + 3*(stress*0.1)**2)

# Quick statistics
print(f"Maximum: {stress.max():.1f} MPa")
print(f"Safety factor: {355/stress.max():.2f}")  # S275 yield strength

# Boolean indexing: cells exceeding the criterion
critical_zones = np.where(von_mises > 300)[0]
print(f"Cells above 300 MPa: {len(critical_zones)}")

NumPy also provides linear algebra (numpy.linalg), random number generation, Fourier transforms (numpy.fft) for vibration frequency analysis, and statistical operations. All vectorized and compiled against BLAS/LAPACK �the same linear algebra libraries used by MATLAB and commercial finite element solvers.

Matplotlib: publication-quality visualization

A well-constructed plot communicates more than a thousand tables. Matplotlib is the standard visualization library of the Python ecosystem and provides total control over every plot element: typography, colors, line styles, annotations and axis formatting. The learning curve is steeper than Excel's, but the result is reproducible and consistent.

For engineering, the recommended approach is to use the object-oriented style (fig, ax) instead of the global state pyplot interface. This avoids confusion when working with multiple simultaneous plots and makes the code explicitly clear about what you are modifying.

import matplotlib.pyplot as plt
import numpy as np

# Professional style configuration
plt.rcParams.update({
    'font.family': 'serif',
    'font.size': 10,
    'axes.labelsize': 11,
    'figure.dpi': 150,
    'savefig.bbox': 'tight'
})

# Data: angle of attack sweep vs lift coefficient
alpha = np.linspace(-5, 15, 41)
cl = 0.1 * alpha + 0.008 * alpha**2  # Linear + non-linear approx

fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(alpha, cl, 'b-', linewidth=2, label='CFD (Spalart-Allmaras)')
ax.axhline(y=0, color='gray', linewidth=0.5)
ax.axvline(x=0, color='gray', linewidth=0.5)
ax.set_xlabel('Angle of attack (degrees)')
ax.set_ylabel('Lift coefficient CL')
ax.set_title('Lift curve of NACA 2412 airfoil')
ax.grid(True, alpha=0.3)
ax.legend()
fig.savefig('lift_curve.pdf')
plt.show()

A practical tip: always save plots as PDF (vector) in addition to PNG. The PDF can be inserted into LaTeX or Word reports without losing quality and can be edited with Inkscape for fine annotation adjustments. PNG is for quick visualization and presentations.

Pandas: structured data analysis

Engineering data is rarely pure arrays �it has tabular structure with columns of different types, missing values, and a need to group and filter. Pandas provides the DataFrame, a two-dimensional table with labeled rows and columns, inspired by R's data frames but with NumPy speed underneath.

The most immediate use case: reading a CSV file exported from simulation software (forces, pressures, temperatures at monitoring points) and generating statistics, filters and plots without touching Excel.

import pandas as pd

# Read CFD monitoring data (OpenFOAM postProcess)
df = pd.read_csv('forces.csv', sep='\t', comment='#',
                 names=['t', 'Fx', 'Fy', 'Fz'])

# Steady-state statistics (last 30% of the simulation)
t_cut = df['t'].iloc[-1] * 0.7
df_ss = df[df['t'] >= t_cut]

print("Mean forces in steady-state regime:")
print(f"  Fx = {df_ss['Fx'].mean():.2f} +/- {df_ss['Fx'].std():.2f} N")
print(f"  Fz = {df_ss['Fz'].mean():.2f} +/- {df_ss['Fz'].std():.2f} N")

# Group and pivot for comparisons
results = pd.DataFrame({
    'config': ['base', 'opt_A', 'opt_B', 'opt_C'],
    'Cd': [0.35, 0.31, 0.33, 0.29],
    'Cl': [0.42, 0.44, 0.40, 0.46],
    'time': [120, 118, 135, 140]  # simulation minutes
})
best = results.loc[results['Cd'].idxmin()]
print(f"Best configuration: {best['config']} (Cd={best['Cd']})")

Pandas also reads directly from Excel (read_excel), SQL databases (read_sql), Parquet files (read_parquet, compressed columnar format ideal for large datasets) and HDF5 (read_hdf, binary format with compression for numerical simulations). Interoperability with the office and industrial ecosystem is complete.

SciPy: the engineer toolbox

SciPy extends NumPy with high-level scientific computing functions: numerical integration, optimization, interpolation, signal processing, differential equations and advanced statistics. If NumPy is the hammer, SciPy is the complete workshop.

Key modules for engineering:

  • scipy.optimize: Nonlinear least squares (curve_fit) for fitting models to experimental data. Constrained optimization (minimize) for parametric design. Root finding (root) for solving nonlinear equilibrium equations.
  • scipy.integrate: Numerical integration (quad, simpson) for areas under load curves, strain energy. ODE solving (solve_ivp) for dynamic systems: transient response of a damper, chemical reaction kinetics.
  • scipy.interpolate: 1D, 2D and N-dimensional interpolation (griddata, RBFInterpolator). Essential for mapping simulation results between non-coincident meshes �for example, transferring pressures from a CFD mesh to an FEM mesh for fluid-structure coupling.
  • scipy.signal: Filters (butter, filtfilt) for cleaning noisy sensor signals. Frequency analysis (welch, spectrogram) for identifying vibration modes in experimental data.
  • scipy.stats: Probability distributions for reliability analysis (Weibull for fatigue, lognormal for wind loading). Hypothesis tests (ttest_ind) for comparing two design configurations with statistical significance.

Automation: from manual Excel to automatic pipeline

The big mental transition for the engineer is going from "I open Excel, paste data, drag formulas, copy plot to the report" to "I run a script and get the finished report." The productivity leap is not doing the same thing faster, but eliminating manual intervention entirely.

Recommended automation pattern:

  1. Centralized input parameters: A YAML or TOML file with all design variables, boundary conditions and file paths. No hardcoded values in the code.
  2. Modular pipeline: Split the workflow into independent, testable functions: read_data(), process(), calculate(), generate_report(). Each function receives explicit parameters and returns results �no side effects or global variables.
  3. Automatic file management: Use pathlib for cross-platform paths, create output directories with timestamps to avoid overwriting previous results, and generate a log file with the parameters used and key results (full traceability).
  4. Unsupervised execution: The script can be launched from the command line with arguments (argparse), run periodically with a scheduler (cron on Linux, Task Scheduler on Windows), or integrated into a CI/CD pipeline to re-run analysis when input data changes.

Interfacing with engineering tools

Python does not replace specialized solvers such as OpenFOAM, CalculiX or Ansys; it complements them by automating everything surrounding the simulation. The interface happens through text files �meshes, boundary conditions, results� that Python reads, generates and modifies without manual intervention.

OpenFOAM: OpenFOAM dictionaries are text files with key-value format. Python can generate them automatically with templates (Jinja2) for parametric studies where each case requires modifying dozens of files. The fluidfoam library (pypi.org) reads OpenFOAM results directly into NumPy arrays without touching ParaView.

CalculiX / Abaqus: .inp input files are structured text. Python can generate parametric meshes (with Gmsh via pygmsh), write the input file with loading conditions, launch the solver via subprocess, and read results from the .dat or .frd file for automatic post-processing.

FreeCAD: Full access to the CAD modeling API from Python. Enables generating parametric geometry, modifying it and exporting to STEP or STL �all from scripts. Integration with the optimization ecosystem (scipy.optimize) enables automatic shape optimization without touching the graphical interface.

Case study: CFD post-processing automation

A real case from an aerodynamic engineering consultancy: 50 CFD simulations (OpenFOAM) of a rear wing with different flap and angle-of-attack configurations. Manual post-processing in ParaView + Excel took 3 days per batch of simulations, with high risk of human error when dragging formulas and copying data.

The Python solution automated the complete process:

import subprocess
import numpy as np
import pandas as pd
from pathlib import Path

def run_case(flap_angle, aoa, velocity=30):
    """Launch an OpenFOAM case with given parameters."""
    case_dir = Path(f"cases/flap{flap_angle}_aoa{aoa}")
    case_dir.mkdir(parents=True, exist_ok=True)

    # Generate OpenFOAM dictionaries from template
    generate_cfd_files(case_dir, flap_angle, aoa, velocity)

    # Run simpleFoam
    subprocess.run(
        ["simpleFoam", "-case", str(case_dir)],
        check=True, capture_output=True
    )

    return case_dir

def extract_coefficients(case_dir):
    """Extract Cd and Cl from OpenFOAM postProcessing."""
    df = pd.read_csv(
        case_dir / "postProcessing/forces/0/forces.dat",
        sep='\t', comment='#', header=None,
        names=['t', 'Fx', 'Fy', 'Fz']
    )
    # Use only the last 20% (steady-state regime)
    cut = int(len(df) * 0.8)
    df_ss = df.iloc[cut:]
    rho, A, U = 1.225, 0.15, 30.0
    q = 0.5 * rho * U**2 * A
    Cd = df_ss['Fx'].mean() / q
    Cl = df_ss['Fz'].mean() / q
    return Cd, Cl

# Parametric sweep
results = []
for flap in [0, 5, 10, 15, 20]:
    for aoa in range(-5, 16, 2):
        print(f"Running flap={flap}deg, AoA={aoa}deg")
        case_dir = run_case(flap, aoa)
        Cd, Cl = extract_coefficients(case_dir)
        results.append({
            'flap': flap, 'AoA': aoa,
            'Cd': Cd, 'Cl': Cl,
            'efficiency': Cl / Cd if Cd > 0 else 0
        })

# Results analysis
df_results = pd.DataFrame(results)
print("\nTop 5 configurations by efficiency:")
print(df_results.nlargest(5, 'efficiency')[['flap', 'AoA', 'efficiency']])

The result: 50 simulations post-processed in 40 minutes of automatic execution. Work that manually took 3 days was reduced to launching a script and visually validating the 3 best cases. The engineer's time was dedicated to analyzing results, not exporting CSVs and pasting formulas. And most importantly: the results are reproducible �any team member can re-run the analysis and obtain exactly the same values.

Resources and learning path

The recommended path for an engineer starting with Python is not a generic programming course, but an itinerary applied to real engineering problems from day one:

  1. Week 1: Install the environment. Write scripts that replace calculator computations: stresses, moments of inertia, unit conversions. Get familiar with variables, functions, loops and conditionals applied to concrete examples.
  2. Week 2: Basic NumPy. Replace design calculation spreadsheets with vectorized arrays. Read data from a sensor or an Excel export with Pandas and generate a plot with Matplotlib.
  3. Week 3: Automate a real repetitive task. The ideal candidate: post-process CFD simulation results, generate mesh convergence tables, or create comparative plots of multiple design iterations.
  4. Week 4: Complete pipeline. Create a script that reads input parameters from a configuration file, runs calculations or simulations unsupervised, and generates a PDF report (with ReportLab or WeasyPrint) or an interactive dashboard (with Streamlit).

References: "Python for Engineers" at pythonforengineers.com for applied fundamentals. The official NumPy and Pandas documentation has excellent tutorials with quantitative examples. The book "Effective Computation in Physics" by Scopatz and Huff is a solid reference for scientific development practices. For CFD specifically, the fluidflowcrb repository on GitHub contains examples of OpenFOAM automation with Python.

The investment in learning Python has a measurable return: an engineer who dedicates 40 hours to training and automates tasks that save them 3 hours per week recovers the investment in 3-4 months. From then on, it is all net productivity gain.