【问题标题】:Use pandas to get county name using fips codes使用 pandas 使用 fips 代码获取县名
【发布时间】:2016-12-25 03:32:08
【问题描述】:

我这里有fips代码:http://www2.census.gov/geo/docs/reference/codes/files/national_county.txt

还有一个如下所示的数据集:

fips_state    fips_county       value

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

如何使用上面链接中的数据和 pandas 获取每行的县名?

【问题讨论】:

    标签: python csv pandas fips


    【解决方案1】:

    只需将两个数据集加载到 DataFrames 中,然后设置适当的索引:

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

    这将为您提供按州+县的 MultiIndex。为两个数据集完成此操作后,您可以简单地映射它们,例如:

    df1['county_name'] = df2.county_name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多