FIPS Codes in Python: A Practical Guide with pandas
Python and pandas are the most common tools for working with federal geographic data. Here's how to handle FIPS codes correctly in your data pipelines.
Python with pandas is the most common environment for working with US federal datasets, and proper FIPS code handling is a fundamental skill. The most important rule: always store FIPS codes as strings, never as integers. The moment you load a county FIPS code as an integer, the leading zero for states 01–09 (Alabama through Connecticut) disappears, and every join against another dataset fails silently.
When reading Census Bureau or BLS CSV files, force FIPS columns to string type explicitly: pd.read_csv('data.csv', dtype={'county_fips': str, 'state_fips': str}). If you're constructing FIPS codes from separate state and county columns, always zero-pad: df['fips'] = df['state'].str.zfill(2) + df['county'].str.zfill(3). For validation, you can verify codes against the county FIPS reference or use the FipsDecoder API pattern to cross-check during development.
For geographic joins, the geopandas library reads Census TIGER/Line shapefiles which use GEOID fields — these are the same FIPS codes, sometimes with additional digits for sub-county geographies. A county shapefile's GEOID matches the 5-digit county FIPS code exactly. Joining tabular data to spatial data: gdf.merge(df, left_on='GEOID', right_on='county_fips'). For the King County, WA polygon, the GEOID is "53033".
The censusdatadownloader and census Python packages handle FIPS geography automatically when you query the Census API. For custom lookups — say, you need to map a list of county names to FIPS codes — the Census Bureau's geocoding API or a local reference table (downloadable from the Census ANSI page) are the most reliable options. Our search tool is useful for ad-hoc verification while building your pipeline. See also the federal datasets guide for which agencies publish what and at which geographic levels.
More Articles
USDA Rural Classifications and FIPS Codes
The USDA's Rural-Urban Continuum Codes classify every US county on a 9-point scale from dense metro to completely rural. Here's how they use FIPS codes.
Feb 11, 2026
FEMA Flood Zone Data: Working with FIPS Geography
FEMA's National Flood Insurance Program and flood hazard data use FIPS codes and community identifiers. Here's how to navigate FEMA's geographic data structure.
Jun 18, 2026
Census Bureau Data and FIPS Codes: A Researcher's Guide
The Census Bureau is the primary publisher and steward of FIPS geographic codes. Here's how their data products use FIPS codes and how to navigate them.
Dec 14, 2025