将大熊猫DF与geopandas Shapefile合并,除了列名除外所有行

发布于 2025-01-22 17:52:15 字数 771 浏览 2 评论 0原文

我正在尝试将pandas dataframe df与geopandas shapefile gdf ​​合并。 每当我尝试将两者合并在一起时,gdf.head()的输出仅显示列的名称,而没有数据行。

这是代码:

import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

df = pd.read_csv('~/Desktop/sds cw/cars.csv')
shape = gpd.read_file('~/Desktop/sds cw/Europe_SWAsia.shp')
shape.rename(columns = {'NAME' : 'Country'}, inplace = True)
gdf = gpd.GeoDataFrame(df.merge(shape, on = 'Country'))
gdf.head()

输出为:

”“在此处输入图像描述”

我以前曾将Pandas与Shapefiles合并,这从未发生过,所以我对原因有些困惑。也许与实际的.csv有关?

任何解决方案都将不胜感激。

I am trying to merge a pandas DataFrame df with a GeoPandas shapefile gdf.
Whenever I try to merge the two together, the output for gdf.head() only shows the column names and no rows of data under it.

Here is the code:

import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

df = pd.read_csv('~/Desktop/sds cw/cars.csv')
shape = gpd.read_file('~/Desktop/sds cw/Europe_SWAsia.shp')
shape.rename(columns = {'NAME' : 'Country'}, inplace = True)
gdf = gpd.GeoDataFrame(df.merge(shape, on = 'Country'))
gdf.head()

The output is:

enter image description here

I have merged Pandas with shapefiles before and this has never happened so I am a bit confused as to why. Maybe it has something to do with the actual .csv?

Any solutions would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文