Geopandas Left Join using Merge – Step-by-Step Guide

attribute-joinsgeopandas

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

Best Answer

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')