I have a list of dataframes, all of the same structure and all are polygons.

How can I add them all together using geopandas?


it seems that this is the right way to do that right now:

rdf = gpd.GeoDataFrame( pd.concat( dataframesList, ignore_index=True) )
  • 10
    Great answer, one improvement: rdf = gpd.GeoDataFrame(pd.concat(dataframesList, ignore_index=True), crs=dataframesList[0].crs). Now new dataframe will also have the same CRS as one of the initial dataframes. Because of using pandas.concat any geographical metadata such as CRS does not get preserved by default. – AleksMat Sep 12 '18 at 16:44
  • This works well - thanks. I did find the append can go astray e.g. when one file has "name" and another has "Name", I ended up with nothing in either column for rows from one file. I couldn't reproduce it reliably so I ended up forcing column names to lower case to simplify the column mashing, which seems to be reliable. – Mike Honey Nov 21 '19 at 1:38
  • 1
    I ought you a beer! Thanks Phillipp_Kats – almrog Jul 6 '20 at 14:49
  • @AleksMat Is there any other geographical metadata besides CRS that we should also copy over to make sure it is preserved? – rasen58 Nov 11 '20 at 16:43
  • 1
    @rasen58 According to GeoDataFrame implementation it seems that the only other metadata information is geometry column name. In a rare case that you don't use the default name "geometry" then you have to consolidate that as well. – AleksMat Nov 12 '20 at 20:27

I just experimented with this - maybe in GeoPandas 0.2.1 and Pandas 0.20.3 it is a bit more concise:

gdf = pd.concat([gdf1, gdf2])

gdf is automatically created as a GeoDataFrame. Of course if there is a chance of conflicting indices you'll want to keep the 'ignore_index=True' parameter.

  • 4
    I just tried this and I can confirm it does not work (using pandas_0.20.3 geopandas_0.3.0). The result is a DataFrame, not a GeoDataFrame. E.g. if you try to use gdf1.to_file(xxx, driver='ESRI Shapefile') you will get an error which says 'DataFrame' object has no attribute 'to_file' – jberrio Jul 18 '18 at 0:48
  • @jberrio thanks for the update! looks like the update to GeoPandas made things more explicit. – Charlie Parr Jul 18 '18 at 18:19
  • 1
    For the flagger that requested moderators remove the Accept checkmark please be aware that this is not possible to do. As a workaround from meta.stackexchange.com/a/187263/215590 I tried deleting the answer, but the answerer requested that it be undeleted. A long term solution for dealing with accepted answers that may no longer be correct has been proposed at meta.stackexchange.com/questions/268666/… – PolyGeo Jul 20 '18 at 23:04
  • This worked fine for me with pandas version: 0.24.2 and geopandas version: 0.5.0 – denson Jun 11 '19 at 17:42
  • 3
    this works for me, the output type is a geodataframe. Using python 3.8.3; pandas 1.0.5; geopandas 0.8.0. – a11 Aug 4 '20 at 16:20

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.