question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropping a column in a geodataframe returns a regular dataframe

See original GitHub issue

Provided 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:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ccamaracommented, Apr 1, 2020

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.

0reactions
martinfleiscommented, Apr 1, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found