The rate column in our open dataset of 309 Utah marketing agencies is text. 153 rows have a value, and those values come in 27 spellings: $100 - $149 / hr, $85/hr, $300+ / hr and so on. Some are bands and some are a single number. The same data sits behind our Utah marketing agency directory.
This post turns that column into a number you can query, using only the Python standard library. No pandas. Every snippet ran on Python 3.11 with SQLite 3.53.1.
Load the CSV
The file is public, so the script reads it straight from GitHub. utf-8-sig handles a byte order mark if there is one.
import csv, io, re, sqlite3, urllib.request from statistics import median URL = "https://raw.githubusercontent.com/fedtman/utah-marketing-agencies/main/utah_marketing_agencies.csv" text = urllib.request.urlopen(URL).read().decode("utf-8-sig") rows = list(csv.DictReader(io.StringIO(text))) Turn a rate band into one number
A band has two ends and a single price has one. The low end exists in both, so the script uses that and calls it the starting rate. In this column the first run of digits is always the low end.
def floor_rate(s): m = re.search(r"\d+", s.replace(",", "")) return int(m.group()) if m else None An empty string returns None, which SQLite stores as NULL. That matters later, because COUNT(rate) skips NULLs and COUNT(*) does not.
The cost of this choice: an agency listed at $100 - $149 / hr and one listed at $100/hr both become 100. Read the results as "starts at".
Clean up the team sizes
Team size has the same problem plus one more. Some rows say 2 - 9 or 10 - 49, and others say Under 49, which overlaps both. The script keeps Under 49 as its own group.
def size_band(s): if not s: return None if s == "Freelancer": return "1 person" if s == "Under 49": return "under 50, not split" top = int(s.split(" - ")[1]) return "2 to 9" if top <= 9 else "10 to 49" if top <= 49 else "50 or more" Register a median
Not every SQLite build includes a median function. create_aggregate lets you add your own: a class with step for each row and finalize for the result.
db = sqlite3.connect(":memory:") db.execute("CREATE TABLE a (name TEXT, city TEXT, rate INT, size TEXT, seo INT)") db.executemany("INSERT INTO a VALUES (?,?,?,?,?)", [ (r["name"], r["city"], floor_rate(r["hourly_rate"]), size_band(r["team_size"]), int(r["svc_seo"])) for r in rows]) class Median: def __init__(self): self.v = [] def step(self, x): if x is not None: self.v.append(x) def finalize(self): return median(self.v) if self.v else None db.create_aggregate("med", 1, Median) The name med keeps it from colliding with a built-in median.
Does a bigger team charge more?
SELECT size, COUNT(*) AS agencies, COUNT(rate) AS with_rate, med(rate) AS median_rate FROM a WHERE size IS NOT NULL GROUP BY size ORDER BY agencies DESC; | size | agencies | with_rate | median_rate |
|---|---|---|---|
| 2 to 9 | 90 | 48 | 100 |
| 10 to 49 | 85 | 47 | 100 |
| under 50, not split | 55 | 33 | 125 |
| 50 or more | 38 | 21 | 100 |
| 1 person | 7 | 4 | 75 |
In this data, no. Agencies with 2 to 9 people and agencies with 50 or more have the same median starting rate, $100 an hour. The freelancer figure rests on 4 rows, so don't quote it.
Which cities cost more?
A median of one or two rows is noise. Without a filter, the top of the list is Lindon at $300, and that is one agency. HAVING sets a minimum:
SELECT city, COUNT(rate) AS n, med(rate) AS median_rate FROM a GROUP BY city HAVING COUNT(rate) >= 8 ORDER BY n DESC; | city | n | median_rate |
|---|---|---|
| Salt Lake City | 36 | 100 |
| Lehi | 18 | 100 |
| Provo | 13 | 150 |
| South Jordan | 8 | 100 |
Provo is the only one of the four above $100. Use COUNT(rate) here instead of COUNT(*), or a city with plenty of agencies and one published rate gets through.
Compare agencies with and without SEO
The dataset has a 0/1 column for each service, so a service comparison is one GROUP BY:
SELECT seo, COUNT(rate), med(rate) FROM a GROUP BY seo; The 119 agencies that name SEO and publish a rate have a median of $100. The 34 without SEO have a median of $137.50. Only 153 of the 309 rows have a rate, so this can't tell you what the other 156 charge.
Get the data
- Browse the agencies: Utah marketing agency directory by Brand Captain
- CSV and JSON: github.com/fedtman/utah-marketing-agencies
- Cite it: 10.5281/zenodo.24512883, CC BY 4.0, "Brand Captain, Utah Marketing Agencies 2026"
