使用 pandas 使用 fips 代码获取县名
Use pandas to get county name using fips codes
我这里有 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
如何使用上面 link 中的数据和 pandas 获取每一行的县名?
只需将两个数据集加载到 DataFrame 中,然后设置适当的索引:
df1.set_index(['fips_state', 'fips_county'], inplace=True)
这为您提供了按州+县分类的多索引。为两个数据集完成此操作后,您可以简单地映射它们,例如:
df1['county_name'] = df2.county_name
我这里有 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
如何使用上面 link 中的数据和 pandas 获取每一行的县名?
只需将两个数据集加载到 DataFrame 中,然后设置适当的索引:
df1.set_index(['fips_state', 'fips_county'], inplace=True)
这为您提供了按州+县分类的多索引。为两个数据集完成此操作后,您可以简单地映射它们,例如:
df1['county_name'] = df2.county_name