!unzip https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_ua10_500k.zip
我正在使用上面的数据集分解geopandas Dataframe 中的行
# Read shapefile
test = gpd.read_file("cb_2018_us_ua10_500k")
# Split Name10 column to extract city & state
test[['city', 'state_names']] = test['NAME10'].str.split(',', 1, expand=True)
# Remove trailing & leading spaces
test[['city', 'state_names']] = test[['city', 'state_names']].apply(lambda x: x.str.strip())
test.head()
UACE10 AFFGEOID10 GEOID10 NAME10 LSAD10 UATYP10 ALAND10 AWATER10 geometry city state_names
0 88732 400C100US88732 88732 Tucson, AZ 75 U 915276150 2078695 MULTIPOLYGON (((-110.81345 32.11910, -110.7987... Tucson AZ
1 01819 400C100US01819 01819 Alturas, CA 76 C 4933312 16517 MULTIPOLYGON (((-120.54610 41.51264, -120.5459... Alturas CA
2 22366 400C100US22366 22366 Davenport, IA--IL 75 U 357345121 21444164 MULTIPOLYGON (((-90.36678 41.53636, -90.36462 ... Davenport IA--IL
3 93322 400C100US93322 93322 Waynesboro, PA--MD 76 C 45455957 88872 MULTIPOLYGON (((-77.50746 39.71577, -77.50605 ... Waynesboro PA--MD
4 02548 400C100US02548 02548 Angola, IN 76 C 23646957 3913803 MULTIPOLYGON (((-85.01157 41.59300, -85.00589 ... Angola IN
我正在尝试按行分解state_names
test.assign(state=test["state_names"].str.split("--")).explode('state')
错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-47-5532b7b6cbdf> in <module>
----> 1 test.assign(state=city_geo["state_names"].str.split("--")).explode('state')
TypeError: explode() takes 1 positional argument but 2 were given
当我尝试不使用几何图形时它就起作用了
一个
如何用几何图形分解geopandas数据框?
1条答案
按热度按时间ulydmbyx1#
在这种情况下,数据可以作为 Dataframe 读入,然后在一些处理之后转换为geopandas Dataframe 。
输出功率