Converting a geopandas geodataframe into a pandas dataframe Converting a geopandas geodataframe into a pandas dataframe python python

Converting a geopandas geodataframe into a pandas dataframe


You don't need to convert the GeoDataFrame to an array of values, you can pass it directly to the DataFrame constructor:

df1 = pd.DataFrame(gdf)

The above will keep the 'geometry' column, which is no problem for having it as a normal DataFrame. But if you actually want to drop that column, you can do (assuming the column is called 'geometry'):

df1 = pd.DataFrame(gdf.drop(columns='geometry'))# for older versions of pandas (< 0.21), the drop part: gdf.drop('geometry', axis=1)

Two notes:

  • It is often not needed to convert a GeoDataFrame to a normal DataFrame, because most methods that you know from a DataFrame will just work as well. Of course, there are a few cases where it is indeed needed (e.g. to plot the data without the geometries), and then the above method is the best way.
  • The first way (df1 = pd.DataFrame(gdf)) will not take a copy of the data in the GeoDataFrame. This will often be good from an efficiency point of view, but depending on what you want to do with the DataFrame, you might want an actual copy: df1 = pd.DataFrame(gdf, copy=True)