Spatially Enabled DataFrames Returns SHAPE Eeven When Using Fields Filter

682
4
11-22-2022 09:40 PM
geoca
by
New Contributor

Using ArcGIS Python API and Spatially Enabled DataFrames

 

import arcpy
import pandas as pd
from arcgis.gis import GIS
fc = "City.gdb\\fire_stations"

sdf3 = pd.DataFrame.spatial.from_featureclass(fc, fields=["ADDRESS","MUN_NAME"])

sdf3.head()

 

 

I am still getting the SHAPE even though I am passing `fields=["ADDRESS","MUN_NAME"]`  in the argument to get only ["ADDRESS","MUN_NAME"] in the df

unnamed.png

Can you please let me know how I can get rid of the SHAPE column?

 

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

arcgis.features module | ArcGIS API for Python

perhaps then you don't need a Spatially Enabled DataFrames


... sort of retired...
BHeist
by
New Contributor III

Agreed! You’re seeing that because you’re using a SEDF

0 Kudos
RogerDunnGIS
Occasional Contributor II

If you don't want the shape column, you can call this after it's created:

sdf3.drop("SHAPE", axis=1, inplace=True)
0 Kudos
DarrenConly
Occasional Contributor

Adding to this thread, it's worth noting that if you explicitly include the SHAPE field in the list of fields you specify, it cause a TypeError. So if you're specifying a subset of fields, make sure you do not include SHAPE in that subset:

emp_fields = ['SHAPE', 'SECTOR', 'COUNT']
df_i = pd.DataFrame.spatial.from_featureclass(Path(gdb_empinv).joinpath(fc), where_clause=wherecl_emp, sr=sref_sacog, fields=emp_fields)

# Returns TypeError: Expected String or Unicode

 

0 Kudos