Excel Formula to Python Converter

Paste an Excel or Google Sheets formula and get a Python function with clean variable names, the right imports and helpers for SUMIFS, VLOOKUP and Excel-style rounding.

Runs in your browserUpdated

Paste with or without the leading =. Commas and semicolons both work as argument separators.

Output

Cell references

References appear here once you enter a formula.

Give references meaningful names (B2 → price). Ranges become lists; multi-column ranges become lists of rows.

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the Excel Formula to Python

  1. Paste an Excel or Google Sheets formula, or pick one from Examples.
  2. Choose the target language — the page starts with Python, and you can switch at any time.
  3. Rename the detected cell references to meaningful variable names, for example B2 → price.
  4. Choose a full function or the bare expression, then copy or download the code. Helper functions are added automatically when a formula needs them.

Moving spreadsheet logic into Python

Data teams regularly rebuild Excel models in Python — to automate a monthly report, feed a pandas pipeline or move a calculation behind an API. Re-typing formulas is slow and risky, because Python and Excel disagree on details like rounding and text comparison. This converter parses the formula with Excel's own precedence rules and writes equivalent, readable Python.

=SUMIFS(D2:D100, B2:B100, "North", C2:C100, ">=1000")

def calculate(d2_d100, b2_b100, c2_c100):
    return sum_ifs(d2_d100, b2_b100, 'North', c2_c100, '>=1000')

The sum_ifs() helper (and the matches_criteria() function it uses) is included above the function, so the output runs as-is.

How Excel functions map to Python

ExcelPython
IF(c, a, b)a if c else b
IFS / SWITCHchained conditional expressions
AND, OR, NOTand, or, not
= and <>== and !=
a & bstr(a) + str(b)
a ^ ba ** b
SUM(A2:A10)sum(a2_a10)
ROUND(x, 2)excel_round() helper — not round()
MOD(a, b)a % b
SUMIFS / COUNTIF…sum_ifs(), count_if() helpers
VLOOKUP / XLOOKUPvlookup(), xlookup() helpers
IFERROR(x, y)if_error(lambda: x, y)
LEFT / MID / LENslicing, len()
TODAY() / NOW()date.today(), datetime.now()

Pitfalls the converter handles

  • Banker's rounding. Python's round(2.5) returns 2 and round(0.125, 2) returns 0.12; Excel gives 3 and 0.13. The output uses an excel_round() helper based on Decimal with ROUND_HALF_UP.
  • Concatenation. "Total: " + 5 raises a TypeError in Python, so every non-text operand of & is wrapped in str().
  • IF is an expression. IF becomes Python's conditional expression (a if c else b), and nested IFs chain naturally.
  • Integer division. Python 3's / always returns a float, matching Excel.
  • Errors. IFERROR becomes if_error(lambda: …, fallback), which catches ZeroDivisionError, LookupError from lookups and other exceptions.
  • Dates. DATE, TODAY and YEAR map to the datetime module. Excel rolls over invalid dates (month 13); Python raises an error, and the converter warns you.

Working with pandas

Generated functions work on scalars and lists. To apply a row-wise formula to a DataFrame, call it with df.apply(lambda r: calculate(r.price, r.qty), axis=1); for aggregates such as SUMIFS, pandas boolean masks (df.loc[(df.region == 'North') & (df.total >= 1000), 'amount'].sum()) are faster on large data.

Supported functions: IF, IFS, SWITCH, AND, OR, NOT, XOR, IFERROR, IFNA, ISBLANK, ISNUMBER, ISTEXT, SUM, AVERAGE, MIN, MAX, COUNT, COUNTA, COUNTBLANK, PRODUCT, MEDIAN, ROUND, ROUNDUP, ROUNDDOWN, INT, TRUNC, ABS, SIGN, MOD, POWER, SQRT, EXP, LN, LOG, LOG10, PI, CEILING, FLOOR, RAND, RANDBETWEEN, SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, AVERAGEIFS, SUMPRODUCT, VLOOKUP, XLOOKUP, MATCH, INDEX, CONCAT, CONCATENATE, TEXTJOIN, LEFT, RIGHT, MID, LEN, UPPER, LOWER, PROPER, TRIM, SUBSTITUTE, REPLACE, FIND, SEARCH, REPT, VALUE, EXACT, TEXT (number formats), TODAY, NOW, DATE, YEAR, MONTH, DAY. Load the spreadsheet itself with Excel to JSON and json.load().

Tools that pair well with the Excel Formula to Python

  • Excel Formula to JavaScript — Paste a spreadsheet formula and get readable JavaScript: a function with named parameters, correct operator precedence and small helper functions for things JavaScript lacks, such as SUMIFS and VLOOKUP.
  • Excel Formula to SQL — Paste an Excel formula and get the equivalent SQL expression or SELECT query — IF and IFS as CASE WHEN, SUMIFS and COUNTIFS as conditional aggregates, and the right string and date functions for your database.
  • Excel Formula to PHP — Paste a spreadsheet formula and get a PHP 8 function: parenthesised ternaries, mb_* string functions, and helpers for lookups, conditional sums and Excel-style MOD.
  • CSV to JSON — Paste CSV or TSV and get a JSON array of objects.

Frequently asked questions

Why does the output use excel_round() instead of round()?
Python rounds halves to the nearest even number (banker's rounding), so round(2.5) is 2. Excel rounds halves away from zero. The helper reproduces Excel exactly.
Does it work with pandas DataFrames?
The functions take plain values and lists. Pass DataFrame columns with .tolist(), or apply a row-wise function with df.apply(…, axis=1).
How is VLOOKUP translated?
As a vlookup(value, table, column, approximate) helper where the table is a list of rows. Exact match (FALSE) compares text case-insensitively like Excel, and a missing value raises LookupError, which IFERROR catches.
Which Python version is required?
Python 3.8 or newer. Only the standard library is used (math, statistics, decimal, re, fnmatch, datetime), and imports are added only when needed.
Is the formula uploaded anywhere?
No. The conversion runs in your browser.

Related tools