Is there a way to do a "left join" when using the "merge" command on a geopandas df to merge by attribute?

The problem I am running into is that I am joining a geopandas df with CA counites to a pandas df that does not contain all the counites. However, I want the final geopandas df to contain all of the counties, but by default the merge command does an inner join. There is no information on the geopandas merge documnetation page: http://geopandas.org/mergingdata.html


When merging by attributes, you are actually using the pandas merge (or join) method or function (see its docstring: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html).

This method has a how keyword to specify whether to do a left/inner/outer/right join:

gdf.merge(df, on='key', how='left')
  • If I run a pandas method on a geopandas df, does it remain a geopandas df or convert to pandas df? – jtam Nov 9 '18 at 18:56
  • Where appropriate (it depends on the exact method), it will remain a GeoDataFrame, as it will in this case of .merge – joris Nov 12 '18 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.