- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 GeoPandas 和 Pandas。我有一个 300,000 行数据框 df,其中有 4 列 + 索引列。
id lat lon geometry
0 2009 40.711174 -73.99682 0
1 536 40.741444 -73.97536 0
2 228 40.754601 -73.97187 0
但是唯一 ID 很少(~200)
我想为每个 (lat,lon) 组合生成一个 shapely.geometry.point.Point 对象,类似于此处所示:http://nbviewer.ipython.org/gist/kjordahl/7129098(见单元格#5),它循环遍历数据帧的所有行;但是对于这么大的数据集,我想将循环限制在更少的唯一 ID 上。
因此,对于给定的 id 值,idvalue(即从第一行开始的 2009)创建 GeoSeries,并将其直接分配给具有 id==idvalue 的所有行
我的代码如下:
for count, iunique in enumerate(df.if.unique()):
sc_start = GeoSeries([Point(np.array(df[df.if==iunique].lon)[0],np.array(df[df.if==iunique].lat)[0])])
df.loc[iunique,['geometry']] = sc_start
但是事情不起作用——几何字段没有改变——我认为是因为 sc_start 的索引与 df 的索引不匹配。
我该如何解决这个问题?我应该坚持整个 df 的循环吗?
最佳答案
我会采取以下方法:
首先找到唯一的 ID 并为此创建一个 GeoSeries of Points:
unique_ids = df.groupby('id', as_index=False).first()
unique_ids['geometry'] = GeoSeries([Point(x, y) for x, y in zip(unique_ids['lon'], unique_ids['lat'])])
然后在匹配的 id 上将这些几何图形与原始数据框合并:
df.merge(unique_ids[['id', 'geometry']], how='left', on='id')
关于python - Pandas 和 GeoPandas 索引和切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30689063/
我使用来自 OpenStreetMap (link) 的形状文件创建了一个简单的 geopandas map 。 import geopandas as gpd map_gdf = gpd.read_
我正在尝试更改 geopandas 数据框的 CRS。目前的 CRS 是: Name: unknown Axis Info [ellipsoidal]: - lon[east]: Longitude
是否有在 Windows PC 上安装 geopandas 的教程(逐步)?或者哪种方式效果更好? 我已经使用 anaconda 尝试了文档中的解决方案,但最终收到错误(甚至按照建议创建环境)。我什至
我正在尝试按照描述设置 geopandas 对象的 crs here . 示例文件可以从here下载。 import geopandas as gdp df = pd.read_pickle('myS
我目前在 Python 中结合使用 Pandas 和 ArcPy 来完成我的 GIS 工作。我最近听说了 Geopandas 并且有兴趣学习使用它作为 ArcPy 的替代品来进行基本的地理处理操作(空
我读了 .csv文件作为数据框,如下所示: import pandas as pd df = pd.read_csv('myFile.csv') df.head() BoroName g
将 geojson 文件加载到 GeoPandas 后,我得到了预期的名为“几何”的列/特征,其中包含多边形和多边形。 如何将此对象作为 json 或 Python 字典再次取出? 在当前形式下,它是
我正在尝试使用 ANACONDA spyder 运行一个简单的 geopandas 代码。但是,我遇到了错误。 我已经包含了代码和错误如下: —— 这是代码: import geopandas as
我有一个点,我想知道哪个多边形最接近该点。我有点和多边形的地理数据。 最佳答案 您可以使用 distance查找到每个多边形的距离并对它们进行排序以检索最近的。 示例 >>> from shapely
如果我有下面的图,如何将颜色图/图例转换为对数刻度? import geopandas as gpd import matplotlib.pyplot as plt world = gpd.read_
我有一个 geopandas 数据框 geometry idx 0 POLYGON ((-74.2555
我在 python 中使用 GeoPandas 并且有一个有效的多边形 GeoDataframe。 0 POLYGON Z ((68.70999999999999 623.1 0, 3
假设我有以下包含 3 个多边形对象的地理数据框。 import geopandas as gpd from shapely.geometry import Polygon p1=Polygon([(0
我有一个 geopandas 数据框,由 id 和由 2D 点填充的几何列组成。我想连接每个唯一 id 的点来创建一个多边形,以便我的新数据框将多边形作为其几何形状。我的代码目前看起来像这样: pol
我想使用geopandas.rotate()函数根据列中的属性旋转geodataframe中的所有要素。如果我只选择一项功能,我就会成功。然而,对于多行,我相信我需要创建一个 for 循环。 new_
我正在尝试在我的 Mac OS X 上安装 geopandas。 我做了什么: • 下载并安装了适用于 Python 2.7 的 Anaconda here .图形安装程序。 • python --v
我一直收到这个错误,并且已经阅读了其他人的在线访问, ImportError: geopandas, pyshp and shapely must be installed for this figu
您好,我正在尝试将 X 和 Y 坐标列表转换为直线。我想通过 groupby ID 和时间来映射这些数据。只要我 grouby 一列,我的代码就可以成功执行,但是两列是我遇到错误的地方。我引用了这个q
我在使用 read_file 函数时遇到了一些关于 geopandas 和 fiona 的问题。这是我的回溯: df = gpd.read_file('/Users/danqing0703/githu
我有一个在 mapshaper 上看起来像这样的 shapefile: 但是当我尝试用下面的代码在 pandas 中绘制它时 police = gpd.read_file('srilanka_poli
我是一名优秀的程序员,十分优秀!