Excel to Python: ADDRESS Function - A Complete Guide | Mito
Home Icon
divider

Functions

divider

Lookup

divider

ADDRESS

How to Use Excel's ADDRESS Function in Pandas

Excel's ADDRESS function: Return cell address as text given row/column.

This guide explains in depth how to replicate Excel's ADDRESS functionality in Python using pandas and numpy.

We will cover syntax, multiple examples, edge cases, performance considerations, common mistakes, and best practices.

To mimic Excel's ADDRESS in pandas, you can use several approaches depending on context.

Below are multiple strategies, each with pros and cons.

These code examples also illustrate performance differences and how to handle missing data.

Simple equivalent of ADDRESS using core pandas methods.

Useful for small datasets and straightforward logic.

import pandas as pd
df = pd.DataFrame({'A':[10,20], 'B':[30,40]})
row, col = 1, 2  # Excel is 1-based
val = df.iloc[row-1, col-1]
cell_address = f"${chr(64+col)}${row}"
print(cell_address, val)
Copy!
Clipboard

For performance-sensitive tasks, numpy can be faster than pandas.

This approach is vectorized and avoids Python loops.

def col_letters(n):
    s=''
    while n>0:
        n, r = divmod(n-1, 26)
        s = chr(65+r)+s
    return s
print(f"${col_letters(28)}$15")  # $AB$15
Copy!
Clipboard

For complex business logic, combine pandas, numpy, and custom functions.

This is useful when porting long Excel formulas into maintainable Python code.

import re, pandas as pd
def address_to_iloc(addr):
    m = re.match(r"\$?([A-Z]+)\$?(\d+)", addr)
    col, row = m.group(1), int(m.group(2))
    # convert letters to 1-based number
    n=0
    for ch in col: n = n*26 + (ord(ch)-64)
    return (row-1, n-1)

print(address_to_iloc('$B$2'))  # (1,1)
Copy!
Clipboard

Here are common mistakes when replicating Excel logic in pandas:

These include indexing errors, type mismatches, handling NaN values, and misinterpreting Excel defaults.

We provide at least three examples for clarity.

Excel uses 1-based indexing, pandas uses 0-based.

# Excel is 1-based, pandas iloc is 0-based:
import pandas as pd
df = pd.DataFrame({'A':[10,20], 'B':[30,40]})
excel_row, excel_col = 2, 2  # B2
value = df.iloc[excel_row-1, excel_col-1]
print(value)
Copy!
Clipboard

Excel coerces types differently than pandas.

import pandas as pd
df = pd.DataFrame({'num':['10','20','x']})
df['num_num'] = pd.to_numeric(df['num'], errors='coerce')
print(df)
Copy!
Clipboard

Excel ignores blanks, pandas uses NaN.

import pandas as pd
df = pd.DataFrame({'A':[1,None,3]})
print(df['A'].fillna(0))  # Excel often treats blanks as 0 in some functions
Copy!
Clipboard

Excel is fine with small datasets, pandas/numpy scale better for large data.

import pandas as pd
df = pd.DataFrame({'A': range(1_000)})
# Avoid row-wise loops:
total_loop = 0
for _, r in df.iterrows():
    total_loop += r['A']
# Prefer vectorization:
total_vec = df['A'].sum()
print(total_vec)
Copy!
Clipboard

The ADDRESS function in Excel allows users to return cell address as text given row/column.

Syntax and parameters are flexible, allowing for optional arguments and different modes of operation.

=ADDRESS(row_num,column_num)

Excel formulas can be combined with other functions, making this versatile in reporting and analysis.

ADDRESS Excel Syntax

ParameterDescriptionData Type
row_numRow numbernumber

Examples

FormulaDescriptionResult
=ADDRESS(1,1)Return $A$1$A$1
=ADDRESS(...)Another common example of ADDRESS in practice.Result depending on context

Don't re-invent the wheel. Use Excel formulas in Python.

Install Mito

Don't want to re-implement Excel's functionality in Python?

Automate analysis with Mito