2

I have fips codes here: http://www2.census.gov/geo/docs/reference/codes/files/national_county.txt

And a dataset that looks like this:

fips_state    fips_county       value

1             1                 10
1             3                 34
1             5                 37
1             7                 88
1             9                 93

How can I get the county name of each row using the data from the link above with pandas?

Mike Johnson Jr
  • 776
  • 1
  • 13
  • 32

1 Answers1

4

Simply load both data sets into DataFrames, then set the appropriate index:

df1.set_index(['fips_state', 'fips_county'], inplace=True)

This gives you a MultiIndex by state+county. Once you've done this for both datasets, you can trivially map them, for example:

df1['county_name'] = df2.county_name
John Zwinck
  • 239,568
  • 38
  • 324
  • 436