Join a pandas dataframe to feature class table by matching column

1999
4
08-07-2022 07:49 AM
Labels (1)
MaxDuso
New Contributor II

Hello there. I have a pandas dataframe and a feature class. The rows of each relate to a set of ecoregions and ecoregions are named in the same way in the "ecoregion_name" column of each. I would like to append, join, insert cursor, or what have you the dataframe to the feature class.

I do not believe that the "arcpy.management.AddJoin" tool supports dataframes. Does it support csv files by chance?

I have also tried using "update cursor" . The issue I encountered here was being unable to access the value of the join field within the "row" for each for loop iteration, so that I could write a conditional statement which made the match happen between the two join columns.

Is there a concise way of doing this without too much data conversion and code that I am missing? Any solution is very appreciated.

 

Thanks.

Max

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

csv as input to Table To Table (Conversion)—ArcGIS Pro | Documentation

then addjoin is one approach, unless you want to keep with the arcgis api


... sort of retired...
0 Kudos
MaxDuso
New Contributor II

Just wondering if I am understanding correctly. You suggest converting the dataframe to a csv, then converting the csv to a gdb using the "Table To Table", at which point it should be able to join to my feature classes table using "AddJoin" as above?

 

To be clear, I jsut want to add the corresponding data from the df to the feature class whic will be my end product here.

 

Thanks or the help.

0 Kudos
DavidAnderson_1701
Occasional Contributor

Here is code sketch

arcpy.management.AddField('MyFeatureClass','NewFC_Field')

fields =['ecoregion_name', 'NewFC_Field']

with arcpy.da.UpdateCursor('MyFeatureClass','fields) as cursor:

   for row in cursor:

        row[1] = Dataframe[Dataframe['ecoregion_name' == row[0]]['DataframeFieldToTransfer']

        cursor.updateRow(row)

0 Kudos
ArianaMo1912
New Contributor III

@MaxDuso where you able to find a solution on your own?

0 Kudos