DataFrame.spatial.from_featureclass column names

1599
6
Jump to solution
02-01-2021 07:30 PM
Labels (1)
MingHan
New Contributor III

Hi Everyone

    For some reason, the column name of the pd.DataFrame.spatial is changed after I saved it to a file.

    Here is before I save it to a file:

MingHan_2-1612236601417.png

    Here is after I save it to a file 

MingHan_1-1612236251280.png

Here is the code 

print(cat_riv_select.columns)
cat_riv_select.spatial.to_featureclass(location=Outputfilename_cat_riv)
print(cat_ply_select.columns)

Is there any option I did not include? 

My ArcGIS pro version is 2.7. 

Thanks

Ming 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

It seems to be working when I test it. What's the "cat_ply_select.columns" object in your code? If you're instantiating it prior to the to_featureclass function, you'll need to re-create it from the newly-exported file.

Try reading the new file with pandas.DataFrame.spatial.from_featureclass() and see if the column name persists.

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
jcarlson
MVP Esteemed Contributor

In the to_featureclass method, there is an optional Boolean parameter santize_columns that defaults to True. Set this parameter to False to keep your column names as you have them written.

If you look at the docs for the sanitize_column_names method itself, you can see that the default option is "snake_case".

- Josh Carlson
Kendall County GIS
MingHan
New Contributor III

Hi Josh 

    I tried the following commands:

 print(cat_riv_select.columns)
cat_riv_select.spatial.to_featureclass(location=Outputfilename_cat_riv,overwrite=True,sanitize_columns=0)
print(cat_ply_select.columns)

    But still get the same outputs....


    

0 Kudos
jcarlson
MVP Esteemed Contributor

It seems to be working when I test it. What's the "cat_ply_select.columns" object in your code? If you're instantiating it prior to the to_featureclass function, you'll need to re-create it from the newly-exported file.

Try reading the new file with pandas.DataFrame.spatial.from_featureclass() and see if the column name persists.

- Josh Carlson
Kendall County GIS
MingHan
New Contributor III

I double test in the ArcGIS notebook, seems it is work there, I guess I got something wrong in my code. Many thanks for your help 

Ming 

MingHan
New Contributor III

I got an error: "to_featureclass() got an unexpected keyword argument 'santize_columns'"

by this:

cat_riv_select.spatial.to_featureclass(location=Outputfilename_cat_riv,santize_columns=False)

Gertvan_Maren1
New Contributor III

Hi,

Did this ever get resolved? I get the same error now.

Thanks Gert

0 Kudos