作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对整个列执行操作,但出现类型错误,我想创建一个包含 Shapely Point 的列:
crime_df = crime_df[crime_df['Latitude'].notna()]
crime_df = crime_df[crime_df['Longitude'].notna()]
crime_df['Longitude'] = crime_df['Longitude'].astype(float)
crime_df['Latitude'] = crime_df['Latitude'].astype(float)
print (crime_df['Longitude'])
print (crime_df['Latitude'])
crime_df['point'] = Point(crime_df['Longitude'], crime_df['Latitude'])
18626 -87.647379
Name: Longitude, Length: 222, dtype: float64
18626 41.781100
Name: Latitude, Length: 222, dtype: float64
TypeError: cannot convert the series to <class 'float'>
最佳答案
我认为您需要分别处理每个点,因此需要 DataFrame.apply
使用 lambda 函数:
crime_df['point'] = crime_df.apply(lambda x: Point(x['Longitude'], x['Latitude'], axis=1)
crime_df["point"] = crime_df[["Longitude", "Latitude"]].apply(Point, axis=1)
crime_df['point'] = [Point(lon, lat)
for lon, lat in crime_df[['Longitude','Latitude']].values]
geopandas.points_from_xy
喜欢:
gdf = geopandas.GeoDataFrame(df,geometry=geopandas.points_from_xy(df.Longitude,df.Latitude))
关于python - 如何将两个坐标列转换为一列 Shapely 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61170839/
我是一名优秀的程序员,十分优秀!