Skip to main content
1 of 2
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()
wilbev
  • 1.7k
  • 9
  • 31
  • 38