Skip to main content
corrected spelling
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

Preserve Column Ordercolumn order of GeopandasGeoPandas file read

I have a shape fileshapefile I'm reading in using geopandasGeoPandas and then I do some geometry conversion of the data but in the process it unfortunately sorts the columns alphabetically. I need to preserve original order of the columns which has over 200 columns. Here

Here is the start of the code I'm using. I imagine I have to somehow store the original column order and apply it to the geopandasGeoPandas dataframe.

import geopandas as gpd 


shpfile = r"C:\data\myfile.shp"
poly = gpd.read_file(shpfile)
poly.head()

Preserve Column Order of Geopandas file read

I have a shape file I'm reading in using geopandas and then I do some geometry conversion of the data but in the process it unfortunately sorts the columns alphabetically. I need to preserve original order of the columns which has over 200 columns. Here is the start of the code I'm using. I imagine I have to somehow store the original column order and apply it to the geopandas dataframe.

import geopandas as gpd
shpfile = r"C:\data\myfile.shp"
poly = gpd.read_file(shpfile)
poly.head()

Preserve column order of GeoPandas file read

I have a shapefile I'm reading in using GeoPandas and then I do some geometry conversion of the data but in the process it unfortunately sorts the columns alphabetically. I need to preserve original order of the columns which has over 200 columns.

Here is the start of the code I'm using. I imagine I have to somehow store the original column order and apply it to the GeoPandas dataframe.

import geopandas as gpd 


shpfile = r"C:\data\myfile.shp"
poly = gpd.read_file(shpfile)
poly.head()
Source Link
wilbev
  • 1.7k
  • 9
  • 31
  • 38

Preserve Column Order of Geopandas file read

I have a shape file I'm reading in using geopandas and then I do some geometry conversion of the data but in the process it unfortunately sorts the columns alphabetically. I need to preserve original order of the columns which has over 200 columns. Here is the start of the code I'm using. I imagine I have to somehow store the original column order and apply it to the geopandas dataframe.

import geopandas as gpd
shpfile = r"C:\data\myfile.shp"
poly = gpd.read_file(shpfile)
poly.head()