Renaming columns using geopandas - issues with data table in ArcGeoPandas to_file() saves GeoDataFrame without coordinate systemFrom text data create a FeatureClass with table with pythonSpeed up row-wise point in polygon with GeopandasRenaming shapefiles using loop in PythonGeopandas: Write layer back into GeoDataBaseConverting shapefile data to .osm using ogr2osmGeopandas not recognizing geometry typeHow do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?gdal/geopandas data object compatibility in pythonSorting (ORDER BY) rows from Shapefile using Python?How to create a shapefile [polygon type] from a Geodataframe, returned from a Oracle Spatial cursor with geometry column type=cx_Oracle.LOB?

Can criminal fraud exist without damages?

Anatomically Correct Strange Women In Ponds Distributing Swords

How to write papers efficiently when English isn't my first language?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Customer Requests (Sometimes) Drive Me Bonkers!

Unexpected indention in bibliography items (beamer)

What are the ramifications of creating a homebrew world without an Astral Plane?

How to escape string to filename? It is in backup a file append date

Opposite of a diet

What does this 7 mean above the f flat

How does the UK government determine the size of a mandate?

How do I go from 300 unfinished/half written blog posts, to published posts?

Overloading istream>> to read comma-separated input

Failed to fetch jessie backports repository

Does "every" first-order theory have a finitely axiomatizable conservative extension?

Personal Teleportation as a Weapon

What happens if you roll doubles 3 times then land on "Go to jail?"

CREATE opcode: what does it really do?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Why escape if the_content isnt?

Why not increase contact surface when reentering the atmosphere?

Is there a problem with hiding "forgot password" until it's needed?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

How does it work when somebody invests in my business?



Renaming columns using geopandas - issues with data table in Arc


GeoPandas to_file() saves GeoDataFrame without coordinate systemFrom text data create a FeatureClass with table with pythonSpeed up row-wise point in polygon with GeopandasRenaming shapefiles using loop in PythonGeopandas: Write layer back into GeoDataBaseConverting shapefile data to .osm using ogr2osmGeopandas not recognizing geometry typeHow do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?gdal/geopandas data object compatibility in pythonSorting (ORDER BY) rows from Shapefile using Python?How to create a shapefile [polygon type] from a Geodataframe, returned from a Oracle Spatial cursor with geometry column type=cx_Oracle.LOB?













1















What I'm trying to achieve:



  • Read in an existing ESRI polygon shapefile

  • Drop an attribute

  • Dissolve by another attribute

  • Rename columns

  • Reorder columns

  • Write out as new shapefile

What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.



Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:



Loading table data



Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.



A column was specified that doesn't exists.



A column was specified that doesn't exists.



So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?



import geopandas as gp

# Read data in
f="my_file"
data = gp.read_file(f)

# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)

# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)

# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns="Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1")

# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]

# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)









share|improve this question






















  • data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

    – Paul H
    5 hours ago











  • I can't share the data but can share the code and you can share fake data that reproduces the issue

    – Paul H
    5 hours ago











  • @PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

    – BERA
    4 hours ago












  • @BERA Oops - forgot rename could take callables.

    – Paul H
    4 hours ago















1















What I'm trying to achieve:



  • Read in an existing ESRI polygon shapefile

  • Drop an attribute

  • Dissolve by another attribute

  • Rename columns

  • Reorder columns

  • Write out as new shapefile

What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.



Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:



Loading table data



Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.



A column was specified that doesn't exists.



A column was specified that doesn't exists.



So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?



import geopandas as gp

# Read data in
f="my_file"
data = gp.read_file(f)

# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)

# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)

# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns="Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1")

# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]

# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)









share|improve this question






















  • data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

    – Paul H
    5 hours ago











  • I can't share the data but can share the code and you can share fake data that reproduces the issue

    – Paul H
    5 hours ago











  • @PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

    – BERA
    4 hours ago












  • @BERA Oops - forgot rename could take callables.

    – Paul H
    4 hours ago













1












1








1








What I'm trying to achieve:



  • Read in an existing ESRI polygon shapefile

  • Drop an attribute

  • Dissolve by another attribute

  • Rename columns

  • Reorder columns

  • Write out as new shapefile

What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.



Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:



Loading table data



Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.



A column was specified that doesn't exists.



A column was specified that doesn't exists.



So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?



import geopandas as gp

# Read data in
f="my_file"
data = gp.read_file(f)

# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)

# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)

# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns="Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1")

# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]

# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)









share|improve this question














What I'm trying to achieve:



  • Read in an existing ESRI polygon shapefile

  • Drop an attribute

  • Dissolve by another attribute

  • Rename columns

  • Reorder columns

  • Write out as new shapefile

What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.



Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:



Loading table data



Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.



A column was specified that doesn't exists.



A column was specified that doesn't exists.



So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?



import geopandas as gp

# Read data in
f="my_file"
data = gp.read_file(f)

# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)

# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)

# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns="Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1")

# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]

# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)






python shapefile geopandas






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









ChrisWillsChrisWills

506




506












  • data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

    – Paul H
    5 hours ago











  • I can't share the data but can share the code and you can share fake data that reproduces the issue

    – Paul H
    5 hours ago











  • @PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

    – BERA
    4 hours ago












  • @BERA Oops - forgot rename could take callables.

    – Paul H
    4 hours ago

















  • data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

    – Paul H
    5 hours ago











  • I can't share the data but can share the code and you can share fake data that reproduces the issue

    – Paul H
    5 hours ago











  • @PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

    – BERA
    4 hours ago












  • @BERA Oops - forgot rename could take callables.

    – Paul H
    4 hours ago
















data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

– Paul H
5 hours ago





data.rename(index=str... renaming the index to a data type is very strange. Take that part out and report back

– Paul H
5 hours ago













I can't share the data but can share the code and you can share fake data that reproduces the issue

– Paul H
5 hours ago





I can't share the data but can share the code and you can share fake data that reproduces the issue

– Paul H
5 hours ago













@PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

– BERA
4 hours ago






@PaulH i belive index=str is correct syntax, see the examples in help section of rename. But I also think that part is not needed.

– BERA
4 hours ago














@BERA Oops - forgot rename could take callables.

– Paul H
4 hours ago





@BERA Oops - forgot rename could take callables.

– Paul H
4 hours ago










1 Answer
1






active

oldest

votes


















3














Looking at your code I can see two things that Arcmap doesn't like:



  • The first one is the space in the field name "building d";

  • The second one - and the cause of the error - is the . in "contaminat":"Contam.".

I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam" solved the problem.






share|improve this answer








New contributor




Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f316876%2frenaming-columns-using-geopandas-issues-with-data-table-in-arc%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Looking at your code I can see two things that Arcmap doesn't like:



    • The first one is the space in the field name "building d";

    • The second one - and the cause of the error - is the . in "contaminat":"Contam.".

    I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam" solved the problem.






    share|improve this answer








    New contributor




    Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      3














      Looking at your code I can see two things that Arcmap doesn't like:



      • The first one is the space in the field name "building d";

      • The second one - and the cause of the error - is the . in "contaminat":"Contam.".

      I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam" solved the problem.






      share|improve this answer








      New contributor




      Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        3












        3








        3







        Looking at your code I can see two things that Arcmap doesn't like:



        • The first one is the space in the field name "building d";

        • The second one - and the cause of the error - is the . in "contaminat":"Contam.".

        I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam" solved the problem.






        share|improve this answer








        New contributor




        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        Looking at your code I can see two things that Arcmap doesn't like:



        • The first one is the space in the field name "building d";

        • The second one - and the cause of the error - is the . in "contaminat":"Contam.".

        I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam" solved the problem.







        share|improve this answer








        New contributor




        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 4 hours ago









        Mouad AlamiMouad Alami

        894




        894




        New contributor




        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Mouad Alami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f316876%2frenaming-columns-using-geopandas-issues-with-data-table-in-arc%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bett Inhaltsverzeichnis Geschichte | Bettformen | Bettgrößen | Andere Bezeichnungen | Bettenmangel | Betten in der bildenden Kunst | Schlafmedizinische Gesichtspunkte | Siehe auch | Literatur | Weblinks | Einzelnachweise | NavigationsmenüBett, Bettstatt, BettstelleCommons: BettBabybetten: Anwendung, Ausstattungsmerkmale und VergleichskriterienWasserbetten. Vorurteile im TestHapfnNursch10.1007/s11818-012-0584-74006250-8AKS4329276-8

            Luksemburg Sisukord Nimi | Asend | Loodus | Riigikord | Haldusjaotus | Rahvastik | Riigikaitse | Majandus | Taristu | Ajalugu | Eesti ja Luksemburgi suhted | Haridus | Kultuur | Vaata ka | Viited | Välislingid | Navigeerimismenüü50° N, 6° EÜlevaade Luksemburgi kaitsealadest.Luksemburgi rahvaarv. Statistikaamet.World Bank'i andmebaasÜlevaade Luksemburgi loodusest.Ülevaade Luksemburgi metsadest.Guy Colling. "Red List of the Vascular Plants of Luxembourg." Travaux scientifiques du Musée national d’histoire naturelle Luxembourg. 2005.Luxembourg’s biodiversity at risk.Maailma kahepaiksete andmebaas.Denis Lepage. "Luxembourg." Avibase.Ülevaade temperatuuridest. Luksemburgi meteoroloogiateenistus.Ülevaade Luksemburgist. Euroopa Liidu esinduse koduleht.Système politique. TerritoireÜlevaade Luksemburgi rahvastikust. Luksemburgi statistikaamet.Luksemburgi rahvastik. Luksemburgi statistikaamet.The World FactbookMonique Borsenberger, Paul Dickes. "Religions au Luxembourg. Quelle évolution entre 1999-2008". Luksemburgi statistikaamet. 2011.Luksemburgi peapiiskopkond. Catholic-Hierarchy.Luksemburgi armee koduleht.Luksemburgi armee relvastus.Eesti Välisministeerium.Luksemburgi rahvastik. Luksemburgi statistikaamet.Luksemburgi Eesti Seltsi koduleht.Helen Eelrand. "Raadio, mis muutis maailma." Eesti Päevaleht. 13. märts 2004.Ülevaade Luksemburgi haridussüsteemist.Ülevaade Luksemburgi keskkoolidest.Luksemburgr

            Valle di Casies Indice Geografia fisica | Origini del nome | Storia | Società | Amministrazione | Sport | Note | Bibliografia | Voci correlate | Altri progetti | Collegamenti esterni | Menu di navigazione46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)Sito istituzionaleAstat Censimento della popolazione 2011 - Determinazione della consistenza dei tre gruppi linguistici della Provincia Autonoma di Bolzano-Alto Adige - giugno 2012Numeri e fattiValle di CasiesDato IstatTabella dei gradi/giorno dei Comuni italiani raggruppati per Regione e Provincia26 agosto 1993, n. 412Heraldry of the World: GsiesStatistiche I.StatValCasies.comWikimedia CommonsWikimedia CommonsValle di CasiesSito ufficialeValle di CasiesMM14870458910042978-6