Database & ML: Connect to Databases, Build ML Models

Query a Neon Postgres database straight from Excel, then run EDA and an XGBoost response model with deciles, ROC and gain charts. Built with xlwings Lite.

Download Excel (.xlsx) Watch Video Guide

What This App Does

#

Two parts, both inside Excel:

  • Database: list tables, pull first or random rows, and run any SQL on a Neon Postgres database, directly from Excel over HTTPS with no server in between
  • Analysis: EDA on any Excel table: summary statistics, count and response rate for every category, correlation matrix, charts
  • Model: XGBoost response model with a stratified train / test split, Gini, deciles with lift, a score per row, ROC and gain charts
  • Ships with a 10,000-row bank marketing sample, so the analysis works without a database
  • The connection string is read from an xlwings Lite environment variable and is not saved in the workbook

Important Note

The model is a worked example, not a point-and-click product. For a new dataset, review the column choices and settings, or work through them with an AI coder.

How to Use

#
  1. Download & open: get the workbook and open xlwings Lite (Home > Add-ins). The HOW_IT_WORKS sheet explains every step; the buttons are on the MASTER sheet.
  2. Try it first: click "4. Run EDA", then "5. Build Model" on the sample table DEF
  3. Connect your database (optional): copy the connection string from the Neon console, then in xlwings Lite add it under Settings > Environment Variables as NEON_DATABASE_URL, scope Local, and restart xlwings Lite
  4. Explore: "1. List Tables", "2. Get Table Data" and "3. Run SQL Query"; the results are Excel tables you can analyze in step 3

How It Works

#

Database connection

  • Python in xlwings Lite runs in the browser, which cannot open a direct database connection
  • Neon offers an HTTPS SQL endpoint that browsers can call, so Excel queries it directly with your connection string
  • For MySQL or another Postgres, put a small web API in front of the database (example code linked below)

Analysis and model

  • All processing runs locally in Python inside Excel
  • XGBoost and scikit-learn run in the browser environment
  • Results are written as Excel tables and charts; the input table is not changed

Resources

xlwings Lite

Built with xlwings Lite

Created by Felix Zumstein, it brings Python into Excel seamlessly - enabling native support for databases, AI agents, LLMs, advanced analytics, ML, APIs, and complete automation workflows.

Bugs,issues,questions? Drop a note: amar@harolikar.com