GEOPANDAS .sjoin 'index_left' 和 'index_right' 不能是正在连接的帧中的名称



我正在尝试对 2 个地理数据框进行空间连接。

这两个索引都是这样的:范围索引(开始=0, 停止=312, 步长=1)

我收到以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-228-d0d0190e2940> in <module>()
----> 1 Sales_new_data_concastinate_SR_coundaries_joines=gpd.sjoin(Sales_new_data_concastinated,SR_locations, op='within',how='left')
~/anaconda3/lib/python3.7/site-packages/geopandas/tools/sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
     51             or any(right_df.columns.isin([index_left, index_right]))):
     52         raise ValueError("'{0}' and '{1}' cannot be names in the frames being"
---> 53                          " joined".format(index_left, index_right))
     54 
     55     # the rtree spatial index only allows limited (numeric) index types, but an
ValueError: 'index_left' and 'index_right' cannot be names in the frames being joined

源 https://github.com/geopandas/geopandas/blob/master/geopandas/tools/sjoin.py

说:

RTREE 空间索引只允许有限的(数字)索引类型,但 Geopandas 中的 # 索引可以是任意 dtype。 因此,现在重置两个索引#并存储对原始索引的引用,以便稍后重新附加。

我到底该做什么?

您可能在其中一个地理数据帧中有名为"index_left"和"index_right"的列。

对于您的特定情况,这可能会很烦人,但这就是空间连接方法当前在 GeoPandas 中的实现方式。 因此,您需要删除它们或重命名它们。

解决方案 1:如果您在左侧或右侧数据框中有一列具有这些名称,则可以使用 rename 方法重命名此列:例如 df = df.rename(columns={'left_index': 'other_name'} .

解决方案 2:删除带有 df = df.drop(['index_right', 'index_left'], axis=1) 的列

相关内容

最新更新