# Split an address column into separate fields with pandas

Source: https://parseaddr.com/split-address-column-pandas
Updated: 2026-11-28

Needs pandas and requests. Each row is one call to POST https://api.parseaddr.com/v1/parse.

```python
import os

import pandas as pd
import requests

session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['PARSEADDR_API_KEY']}"
FIELDS = ["unit", "house_number", "road", "city", "postcode", "country"]


def parse(address):
    r = session.post("https://api.parseaddr.com/v1/parse", json={"address": address}, timeout=10)
    r.raise_for_status()
    parsed = r.json()["parsed"]
    return pd.Series({f: parsed.get(f) for f in FIELDS})


df = pd.read_csv("orders.csv")
df = df.join(df["address"].apply(parse))
df.to_csv("orders_split.csv", index=False)
print(df[["order_id"] + FIELDS].to_string(index=False))
```

Output for three rows:

```
 order_id   unit house_number         road   city postcode country
     1001 flat 2           10   downing st london sw1a 2aa     NaN
     1002    NaN         221b baker street london   nw16xe     NaN
     1003    NaN            5  hauptstraße berlin    10115 germany
```

- Values come back lower case and as written (nw16xe keeps no space).
- country is empty when the address names none; send "country": "gb" and read country_code.
- Free key: 2,000 calls a month, 10 a second. 429 carries Retry-After.

## Same split in Google Sheets

The Parserator add-on for Sheets (https://workspace.google.com/marketplace/app/parserator_parse_and_split_addresses/945974620840) is built on usaddress, which is written for US addresses. On the 200 UK addresses in the comparison, usaddress got 0 fully right (https://parseaddr.com/parseaddr-vs-usaddress). This Apps Script adds a =PARSEADDR() formula that calls parseaddr instead.

1. In the sheet, open Extensions > Apps Script, paste the code and save.
2. In Project Settings > Script properties, add PARSEADDR_API_KEY with your key.
3. In B2 type =PARSEADDR(A2:A100). Six columns fill to the right: unit, house number, road, city, postcode, country.

```javascript
// Google Sheets: Extensions > Apps Script, paste this, save.
// Project Settings > Script properties: add PARSEADDR_API_KEY = your key.
// In a cell: =PARSEADDR(A2:A100)  -> unit, house_number, road, city, postcode, country
const FIELDS = ["unit", "house_number", "road", "city", "postcode", "country"];

function PARSEADDR(input) {
  const key = PropertiesService.getScriptProperties().getProperty("PARSEADDR_API_KEY");
  const rows = Array.isArray(input) ? input.map(r => String(r[0]).trim()) : [String(input).trim()];
  const cache = CacheService.getScriptCache();
  const out = rows.map(a => (a ? JSON.parse(cache.get(a.slice(0, 200)) || "null") : FIELDS.map(() => "")));
  const todo = rows.map((a, i) => i).filter(i => out[i] === null);
  for (let s = 0; s < todo.length; s += 10) {               // free key: 10 calls a second
    if (s > 0) Utilities.sleep(1000);
    const batch = todo.slice(s, s + 10);
    const res = UrlFetchApp.fetchAll(batch.map(i => ({
      url: "https://api.parseaddr.com/v1/parse", method: "post", contentType: "application/json",
      headers: { Authorization: "Bearer " + key }, payload: JSON.stringify({ address: rows[i] }),
      muteHttpExceptions: true,
    })));
    res.forEach((r, j) => {
      const i = batch[j];
      if (r.getResponseCode() !== 200) { out[i] = ["error " + r.getResponseCode(), "", "", "", "", ""]; return; }
      const p = JSON.parse(r.getContentText()).parsed;
      out[i] = FIELDS.map(f => p[f] || "");
      cache.put(rows[i].slice(0, 200), JSON.stringify(out[i]), 21600);  // 6 hours: recalcs cost nothing
    });
  }
  return out;
}
```

Output for the same three rows (unit, house_number, road, city, postcode, country):

```
flat 2 | 10   | downing st   | london | sw1a 2aa |
       | 221b | baker street | london | nw16xe   |
       | 5    | hauptstraße  | berlin | 10115    | germany
```

- Each address is cached for 6 hours with CacheService, so a recalculation does not spend calls again.
- Calls go out 10 at a time with a 1 second pause (free key: 10 calls a second). Sheets stops a custom formula after 30 seconds, so keep each formula to 200 rows or fewer.
- A failed row shows the HTTP code, for example "error 401" (wrong key) or "error 429" (over the limit).

