将大熊猫DF与geopandas Shapefile合并,除了列名除外所有行
我正在尝试将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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论