Dropping a column in a geodataframe returns a regular dataframe
See original GitHub issueProvided a geopandas
’ geodataframe, whenever I drop a column like I do with a regular pandas dataframe (see code below), it gets transformed into a regular dataframe, and hence, losing its geospatial properties. Is there any way to prevent that?
In [23]:type(gdf)
Out [23]: geopandas.geodataframe.GeoDataFrame
In [24]: gdf = gdf.drop(columns=['tmp_category'])
In [25]: type(gdf)
Out [26]: pandas.core.frame.DataFrame
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
geopandas.GeoDataFrame
Drop specified labels from rows or columns. Return DataFrame with duplicate rows removed. Return Series/DataFrame with requested index / column level(s) ...
Read more >pandas.DataFrame.drop — pandas 0.21.1 documentation
Return new object with labels in requested axis removed. Parameters: labels : single label or list-like. Index or column labels to drop.
Read more >Converting a geopandas geodataframe into a pandas dataframe
A note - gdf.drop(columns='geometry') with the columns keyword only works since pandas version 0.21 which is relatively recent. It doesn't ...
Read more >Pandas Drop Columns from DataFrame - Spark by {Examples}
pandas.DataFrame.drop() method is used to remove the columns from the DataFrame, by default it doesn't remove on the existing DataFrame instead it returns....
Read more >Pandas: How to Drop a Dataframe Index Column - Datagy
Dropping a Pandas Index Column Using reset_index ... The most straightforward way to drop a Pandas dataframe index is to use the Pandas...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your explanations and sorry of the inconvenience. It is good to know about geopandas behaviour (it may seem obvious for you, but it wasn’t for me due to the fact that is not what I have been experiencing in R) as well as how you prefer to deal with issues and questions (which largely differ from project to project).
Oh, and by the way, thanks for developing and maintaining (I’ve been greatly surprised on how fast and nicely you have dealt with this issue) geopandas, which I realise I will be using on a daily basis for my python projects.
GeoDataFrame stores geometry within the same DataFrame as every other data. GeoDataFrame without geometry column is not considered as valid, hence it may be returned as DataFrame in some occasions. I believe that resolves the issue, so I am closing it now. Next time there’s no need to open an issue, we are monitoring StackOverflow, so I also seen your question there as well. SO is a better place for this kind of debugging.