RecursionError: maximum recursion depth exceeded in comparison while working with pandas
RecursionError: maximum recursion depth exceeded in comparison while working with pandas
我正在处理一些地理数据。我想从我已经拥有的经纬度中获取一个点对象。我的代码如下所示:
for i in range(len(map_polygon)):
x = map_polygon.at[i, 'lon']
y = map_polygon.at[i, 'lat']
map_polygon.at[i, 'point'] = Point(x, y)
但是,我收到以下错误:
RecursionError:比较时超出最大递归深度
我做错了什么?数据框的长度只有大约20k行。
谢谢!
PS 我在下面附上了整个错误消息:
map_polygon.at[i, 'point'] = Point(x, y)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 2167, in __setitem__
return super().__setitem__(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 2118, in __setitem__
self.obj._set_value(*key, value=value, takeable=self._takeable)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py", line 3278, in _set_value
self.loc[index, col] = value
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 692, in __setitem__
iloc._setitem_with_indexer(indexer, value, self.name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1635, in _setitem_with_indexer
self._setitem_with_indexer_split_path(indexer, value, name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1720, in _setitem_with_indexer_split_path
self._setitem_single_column(loc, value, pi)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1813, in _setitem_single_column
ser._mgr = ser._mgr.setitem(indexer=(pi,), value=value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 568, in setitem
return self.apply("setitem", indexer=indexer, value=value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 427, in apply
applied = getattr(b, f)(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
[Previous line repeated 977 more times]
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 966, in setitem
dtype, _ = maybe_promote(np.array(value).dtype)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geometry/point.py", line 111, in array_interface
if self.is_empty:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geometry/base.py", line 699, in is_empty
return (self._geom is None) or bool(self.impl['is_empty'](self))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/predicates.py", line 25, in __call__
return self.fn(this._geom)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geos.py", line 583, in errcheck_predicate
if result == 2:
RecursionError: maximum recursion depth exceeded in comparison
添加几何列时,循环并单独设置每个值通常不是一个好主意(速度慢),因此您可能希望这样做:
map_polygon['point'] = [Point(p) for p in zip(df.lon, df.lat)]
我正在处理一些地理数据。我想从我已经拥有的经纬度中获取一个点对象。我的代码如下所示:
for i in range(len(map_polygon)):
x = map_polygon.at[i, 'lon']
y = map_polygon.at[i, 'lat']
map_polygon.at[i, 'point'] = Point(x, y)
但是,我收到以下错误: RecursionError:比较时超出最大递归深度
我做错了什么?数据框的长度只有大约20k行。
谢谢!
PS 我在下面附上了整个错误消息:
map_polygon.at[i, 'point'] = Point(x, y)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 2167, in __setitem__
return super().__setitem__(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 2118, in __setitem__
self.obj._set_value(*key, value=value, takeable=self._takeable)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py", line 3278, in _set_value
self.loc[index, col] = value
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 692, in __setitem__
iloc._setitem_with_indexer(indexer, value, self.name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1635, in _setitem_with_indexer
self._setitem_with_indexer_split_path(indexer, value, name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1720, in _setitem_with_indexer_split_path
self._setitem_single_column(loc, value, pi)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexing.py", line 1813, in _setitem_single_column
ser._mgr = ser._mgr.setitem(indexer=(pi,), value=value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 568, in setitem
return self.apply("setitem", indexer=indexer, value=value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 427, in apply
applied = getattr(b, f)(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 967, in setitem
return self.astype(dtype).setitem(indexer, value)
[Previous line repeated 977 more times]
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 966, in setitem
dtype, _ = maybe_promote(np.array(value).dtype)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geometry/point.py", line 111, in array_interface
if self.is_empty:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geometry/base.py", line 699, in is_empty
return (self._geom is None) or bool(self.impl['is_empty'](self))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/predicates.py", line 25, in __call__
return self.fn(this._geom)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geos.py", line 583, in errcheck_predicate
if result == 2:
RecursionError: maximum recursion depth exceeded in comparison
添加几何列时,循环并单独设置每个值通常不是一个好主意(速度慢),因此您可能希望这样做:
map_polygon['point'] = [Point(p) for p in zip(df.lon, df.lat)]