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
FIPS Codes vs ZIP Codes: Key Differences for Data Work
ZIP codes and FIPS codes both identify US geography, but they serve very different purposes. Here's what every data analyst needs to know.
Nov 27, 2025
FIPS Codes in R: Using tidycensus and tigris
The tidycensus and tigris packages make FIPS-based Census data analysis accessible in R. Here's how to use them effectively.
Jan 17, 2026
BLS QCEW Employment Data: Working with County FIPS Codes
The Bureau of Labor Statistics Quarterly Census of Employment and Wages is one of the most comprehensive county-level datasets available. Here's how to work with its FIPS geography.
Dec 22, 2025