'Merging Pandas DF with a Geopandas Shapefile removes all the rows except column names
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

