What is wrong with my spatial.to_featureclass() syntax?

1458
2
11-08-2019 02:53 PM
Matthew_Williams
New Contributor III

I am trying to use Pandas data frames to filter features as using the equivalent geoprocessing tools (select, append) take multiple hours to run. The script reads in my feature class just fine, but outputting to a new feature class produces the following error: 

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

intersectionsSdf = pd.DataFrame.spatial.from_featureclass(intersections)

selection = intersectionsSdf.loc[intersectionsSdf[sc].isin(verifiedSites)]

selection.spatial.to_featureclass(r'MYPATH\MYGDB.gdb\VerifiedSelectionLayer', overwrite=True)

Note: 'verifiedSites' is just a list of integers- this seems to not be a problem as printing the dataframe works fine, but outputting to an FC fails

Can someone help me troubleshoot this? As far as I can tell it may be something to do with the ordering of my inputs? It ran one time with no errors, but I cannot reproduce this result

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

You are comparing many to many, but without a proper array formulation, you can run into problems

You might want to test for inclusion on an elemental basis prior to the slice on the second line so emulate the following between lines 1 and 2

a = [1,2,3,4,5]

b = [1,2,3]

# ---- the wrong way

b in a
False

# ---- the safe way
is_in = [i for i in b if i in a]
[1, 2, 3]‍‍‍‍‍‍‍‍‍‍‍‍
Matthew_Williams
New Contributor III

Hi Dan- thanks very much for your reply. To clarify, does line 11 essentially say "is_in is equal to i for i in b, but only if i is also in a"?

The issue doesn't seem to be the creation of the dataframe- I can print 'selection' with no issues. It seems to arise only when I try to output that frame to a feature class... could the be an issue with saving to a geodatabase rather than a shapefile?

0 Kudos