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

Dmi*_*kin 11 python python-3.x geopandas

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

\n\n

两个索引都是这种类型:\nRangeIndex(start=0, stop=312, step=1)

\n\n

我收到以下错误:

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

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

\n\n

说:

\n\n
\n

rtree 空间索引仅允许有限的(数字)索引类型,但 geopandas 中的 # 索引可以是任意数据类型。因此,现在重置两个索引并存储对原始索引的引用,以便稍后重新固定。\xe2\x80\x93

\n
\n\n

我实际上要做的是什么?

\n

jor*_*ris 16

您的 GeoDataFrame 之一中可能有名为“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)