Select to view content in your preferred language

Changing a Field's Data Type

310
2
Jump to solution
06-12-2024 09:24 AM
Labels (1)
John_Herrera
New Contributor III

I'm working with spatially enabled dataframes (sdf) to develop a workflow using ArcGIS API for Python. In the sdf, I have a field name, facility_id, which has a field type, Float64. I've changed the field type to Int64. When I print a list of field types, facility_id has the old field type, Float64. See attached image to view outputs.  Any help is greatly appreciated!

# Change field type
sdf.astype({'facility_id': 'Int64'}).dtypes

# list field types by field name
sdf.dtypes

0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

The problem here is that operation doesn't happen in-place. So, you have to do this to bake into the dataframe:

sdf = sdf.astype({'facility_id': 'Int64'})

 

You may also use this syntax if you find it less confusing:

sdf["facility_id"] = sdf["facility_id"].astype("Int64")

 

View solution in original post

2 Replies
EarlMedina
Esri Regular Contributor

The problem here is that operation doesn't happen in-place. So, you have to do this to bake into the dataframe:

sdf = sdf.astype({'facility_id': 'Int64'})

 

You may also use this syntax if you find it less confusing:

sdf["facility_id"] = sdf["facility_id"].astype("Int64")

 

John_Herrera
New Contributor III

The second piece of code works perfectly!  Thank you for time.  It's greatly appreciated!

0 Kudos