Fixing Crossing Collisions That Do Not Join to the Crossing Inventory

On this page

Problem statement

Joining the FRA's collision reports to its crossing inventory should be a plain merge on the crossing id, but a twentieth of the reports find no crossing. In the 29 October 2026 copies, 251,520 reports join 238,186 times. 5,512 have no id, 3,823 hold something that is not an id, and 3,999 hold a well-formed id the inventory does not contain. This page sorts out the three kinds, shows that almost all of them are from the 1970s to the 1990s, and does the join so that it fails loudly when the inventory's own duplicate ids would multiply rows.

Quick answer

Test each report's id against the inventory's pattern and its list of ids, then join the ones that match:

valid = inc.gradecrossingid.str.fullmatch(r"[0-9]{6}[A-Z]", na=False)
known = inc.gradecrossingid.isin(xing.crossingid)
print(f"reports: {len(inc):,}; no id: {inc.gradecrossingid.isna().sum():,}; not an id: {(inc.gradecrossingid.notna() & ~valid).sum():,}; valid but unknown: {(valid & ~known).sum():,}")
j = inc[known].merge(xing.drop_duplicates("crossingid", keep="last"), left_on="gradecrossingid", right_on="crossingid", how="left", suffixes=("", "_x"))
print(f"joined: {len(j):,} ({known.mean():.1%})")
reports: 251,520; no id: 5,512; not an id: 3,823; valid but unknown: 3,999
joined: 238,186 (94.7%)

238,186 reports, 94.7%, join to a crossing. The other three groups need different handling: no id at all, a placeholder or damaged id, and a valid id for a crossing the inventory no longer holds.

Horizontal bars of collision reports: 238,186 joined to a crossing, 5,512 with no id, 3,823 with a placeholder or damaged id, 3,999 with a valid id not in the inventory. Horizontal bars of collision reports: 238,186 joined to a crossing, 5,512 with no id, 3,823 with a placeholder or damaged id, 3,999 with a valid id not in the inventory.
Reports by whether they join.

Why a report has no crossing

1. Placeholders instead of ids

print(inc.gradecrossingid[inc.gradecrossingid.notna() & ~valid].value_counts().head(8).to_dict())
{'NOTASGN': 1950, 'RRYARD': 195, 'YARD': 56, 'DUS0TRY': 35, 'RIVA0TE': 31, 'NO-GXID': 29, 'NOT-ASN': 28, 'PRIVATE': 23}

The commonest non-id is NOTASGN, not assigned, 1,950 times, with spellings like NOT-ASN and NO-GXID. RRYARD and YARD mark collisions in rail yards, where the road is often a private yard road with no crossing number. DUS0TRY and RIVA0TE are "industry" and "private" squeezed into seven characters, with a zero for a letter. None of these can be repaired into an id; keep them as a category of their own.

2. Short ids

bad = inc.gradecrossingid[inc.gradecrossingid.notna() & ~valid]
print(bad.str.len().value_counts().sort_index().head(8).to_dict())
print(bad[bad.str.fullmatch(r"[0-9]{1,5}[A-Z]")].head(6).tolist())
{1: 3, 2: 3, 3: 43, 4: 128, 5: 135, 6: 745, 7: 2766}
['75S', '42A', '63T', '27L', '55F', '04Y']

Most non-ids are seven characters long, the placeholders above. The short ones, 3 to 6 characters, are ids that lost their leading digits, like 75S and 42A. They cannot be rebuilt: padding 75S with zeros gives 00075S, which is the wrong length and not the crossing it came from.

Horizontal bars of placeholder values in the crossing id column: NOTASGN 1,950, RRYARD 195, YARD 56, DUS0TRY 35, RIVA0TE 31, NO-GXID 29, NOT-ASN 28, PRIVATE 23. Horizontal bars of placeholder values in the crossing id column: NOTASGN 1,950, RRYARD 195, YARD 56, DUS0TRY 35, RIVA0TE 31, NO-GXID 29, NOT-ASN 28, PRIVATE 23.
Placeholders instead of ids.

3. The years they come from

lost = inc[~known]
print((lost.year // 10 * 10).value_counts().sort_index().to_dict())
print(f"share not joining, 1975-1979: {(~known[inc.year < 1980]).mean():.1%}; 2010 on: {(~known[inc.year >= 2010]).mean():.1%}")
{1970: 7863, 1980: 3659, 1990: 1486, 2000: 305, 2010: 10, 2020: 11}
share not joining, 1975-1979: 12.1%; 2010 on: 0.1%

7,863 of the reports that do not join come from the 1970s, 3,659 from the 1980s and 1,486 from the 1990s. After 2010 only 21 do. 12.1% of the reports from 1975 to 1979 fail to join, against 0.1% from 2010 on. The crossing numbering system was still being filled in when the earliest reports were filed, and many crossings closed since were never matched to their old reports. Any analysis that needs the crossing's attributes is therefore on firmer ground from about 2000 on.

Joining what can be joined

The data used on this page

The Federal Railroad Administration (FRA) publishes the Highway-Rail Crossing Inventory (Form 71, one current record for every crossing that is or was in use) and the highway-rail grade crossing incident reports (Form 57, every collision a railroad has reported since 1975) on the Department of Transportation's open data portal. The copies used here were downloaded on 29 October 2026 and saved on this site, because both tables are updated every day; they keep the columns these pages use and leave out the narratives and the contact telephone numbers. Public domain. The setup keeps the inventory's duplicate rows on purpose, to show what they do to a join.

from pathlib import Path
import zipfile

import pandas as pd
import requests

Path("data").mkdir(exist_ok=True)
# Federal Railroad Administration: the Highway-Rail Crossing Inventory (Form 71, the current record of every crossing,
# 47 of its 265 columns) and the highway-rail grade crossing incident reports (Form 57, 1975 on, 51 of 154 columns,
# without the narrative), with the Census Bureau's 2024 county estimates, counties and states.
# Saved 29 October 2026: both tables change every day.
# Live: https://data.transportation.gov/resource/m2f8-22s6.csv and https://data.transportation.gov/resource/7wn6-i5b9.csv
ARCHIVE = "fra-crossings-2026-10-29.zip"
if not Path(f"data/{ARCHIVE}").exists():
    Path(f"data/{ARCHIVE}").write_bytes(requests.get(f"https://data.spatialworkflow.io/{ARCHIVE}", timeout=600).content)
Z = zipfile.ZipFile(f"data/{ARCHIVE}")
xing = pd.read_csv(Z.open("fra-crossing-inventory-2026-10-29.csv"), dtype={"crossingid": str, "statecode": str, "countycode": str, "latitude": str, "longitude": str}, low_memory=False)
xing = xing.sort_values("revisiondate")
inc = pd.read_csv(Z.open("fra-crossing-incidents-2026-10-29.csv"), dtype={"gradecrossingid": str, "statecode": str, "countycode": str, "incidentnumber": str}, low_memory=False)
inc = inc.drop_duplicates()
print(f"inventory rows: {len(xing):,}; incident reports: {len(inc):,}")
inventory rows: 438,910; incident reports: 251,520

Example 1: a one-to-one join

print(f"ids in the inventory twice: {xing.crossingid.duplicated().sum()}")
inv = xing.drop_duplicates("crossingid", keep="last")
j = inc.merge(inv[["crossingid", "crossingclosed", "crossingposition", "countroadwaygatearms"]], left_on="gradecrossingid",
              right_on="crossingid", how="left", validate="many_to_one", indicator=True)
print(j._merge.value_counts().to_dict())
print(j[j._merge == "both"].crossingclosed.value_counts().to_dict())
ids in the inventory twice: 10
{'both': 238186, 'left_only': 13334, 'right_only': 0}
{'No': 196868, 'Yes': 41318}

The inventory has ten ids twice. Merging on it unchanged would duplicate every collision at those crossings, and validate="many_to_one" would refuse. Keeping the last revision of each id makes the right side unique, and the join gives 238,186 matches and 13,334 reports with no crossing. 41,318 of the matched collisions were at crossings that have since closed, so filtering the inventory to open crossings before joining would quietly drop them.

Bars of the share of reports that do not join by year, over a quarter in 1975, falling to a few percent through the 1980s and 1990s and near zero after 2010. Bars of the share of reports that do not join by year, over a quarter in 1975, falling to a few percent through the 1980s and 1990s and near zero after 2010.
Reports that do not join, by year.

Example 2: the state and county agree

both = j[j._merge == "both"].merge(inv[["crossingid", "statecode", "countycode"]], on="crossingid", suffixes=("", "_inv"))
same = both.statecode.str.zfill(2) + both.countycode.str.zfill(3) == both.countycode_inv
print(f"report's county equals the inventory's: {same.mean():.1%}")
report's county equals the inventory's: 95.4%

For matched reports, the state and county on the report agree with the inventory's in 95.4% of cases. The rest are mostly crossings near county lines, or ones whose county was corrected in the inventory after the collision. When a map needs the county, take it from the inventory where the join succeeds and from the report where it does not.