根据值拆分数据帧

我有一个 DataFrame,我想将其拆分为两个不同的 DataFrame,以便稍后使用 GeoPandas 绘制它们。

    price       Latutude     Longitude  yr_built        geometry                pl
0   530000.0    -122.394    -122.394    1900    POINT (-122.39400 47.67000)     13.180632
1   740500.0    -122.368    -122.368    1900    POINT (-122.36800 47.69810)     13.515081
2   625000.0    -122.390    -122.390    1900    POINT (-122.39000 47.58720)     13.345507
3   595000.0    -122.345    -122.345    1900    POINT (-122.34500 47.65820)     13.296317
4   485000.0    -122.370    -122.370    1900    POINT (-122.37000 47.63850)     13.091904

从 1900 年到 2015 年有 yr_built。

我试着这样拆分:

geoSub1910_1960 = pd.DataFrame()
geoSub1961_2015 = pd.DataFrame()

gdf['yr_built']= gdf['yr_built'].astype(int)

for i in range(len(gdf)):
    print(gdf.iloc[i,:])
    print('this is seperated')
    if gdf['yr_built'] <= 1960:
        geoSub1910_1960.append(gdf.iloc[i,:],ignore_index=True)
    else:
        geoSub1961_2015.append(gdf.iloc[i,ignore_index=True)

我得到的错误是:

ValueError:系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。

scorpiochenyr 回答:根据值拆分数据帧

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1511.html

大家都在问