<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Join a dataframe to layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228484#M66018</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I will try to summarize this as best as possible. I am essentially looking to join survey data to a shapefile! shouldn't be so hard..but I have been left stumped as to why the Join tool is leading me to duplicated rows. I've tried Dissolving the data on the repeated values (such as Shape_Area) but I lose all the columns from the survey data in the output - did another join to the newly dissolved output and again missing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the shapefile row count is 104 and the csv of the survey data is 178 rows. So essentially I want to do a 1-many match on the unique identifier, in my example which is responde (essentially respondent id). I thought about maybe doing this in Pandas but it doesn't look like arcpy and pandas are friends yet but I found one of&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;'s suggestions &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/join-dataframe-with-layer/m-p/1109562/highlight/true" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following his instructions I think the arcpy.da.ExtendTable function could work well however, I'm not well versed with numpy and I'm having problems setting up my column names, or as numpy calls them "dtype".&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example ESRI provides is pretty basic with just three values in the array, whereas my csv is 178 rows with quite a lot of data. I have been trying to pass on the dtype names + format with no success.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/extendtable.htm" target="_self"&gt;ESRI Example:&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_0-1667504007537.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55222iC7D5881DA3FF7BFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_0-1667504007537.png" alt="WillemVan_Riet1_0-1667504007537.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is my code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# df = the csv of survey data

df2 = df[['respondent,C,254', 'category', 'value', 'value_cat', 'unique_ID']]
array = df2.to_records()
print(array)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_1-1667504178320.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55225iAB8FC130D51047CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_1-1667504178320.png" alt="WillemVan_Riet1_1-1667504178320.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# apply the dtype attribute
result = df2.dtypes

print("Output:")
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_2-1667504220944.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55227i974ACBC21F456635/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_2-1667504220944.png" alt="WillemVan_Riet1_2-1667504220944.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# try to create a dictionary of my column names this step may be redundant because I have the result variable above

# dts = {'names': ('Unnamed: 0','respondent,C,254','category', 'value', 'value_cat', 'unique_ID'),
#        'formats':(numpy.int64, numpy.object, numpy.object, numpy.object, numpy.object,
#                  numpy.int64)}
array_table = numpy.rec.fromrecords(array, dtype=dts)

# Convert array to a geodatabase table
table = filepath + '\\table_test'
#check that this is a valid filepath
print(table)

arcpy.da.NumPyArrayToTable(array_table, table)

# Append the array to an existing table on responde (shp) to respondent,c,254(csv)
arcpy.da.ExtendTable(cultural_shp, "responde", array, "respondent,C,254")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are my errors - have I not formatted my array correctly?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_3-1667504699617.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55231iAAEDA54ECB562987/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_3-1667504699617.png" alt="WillemVan_Riet1_3-1667504699617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2022 19:49:06 GMT</pubDate>
    <dc:creator>WillemVan_Riet1</dc:creator>
    <dc:date>2022-11-03T19:49:06Z</dc:date>
    <item>
      <title>Join a dataframe to layer</title>
      <link>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228484#M66018</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I will try to summarize this as best as possible. I am essentially looking to join survey data to a shapefile! shouldn't be so hard..but I have been left stumped as to why the Join tool is leading me to duplicated rows. I've tried Dissolving the data on the repeated values (such as Shape_Area) but I lose all the columns from the survey data in the output - did another join to the newly dissolved output and again missing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the shapefile row count is 104 and the csv of the survey data is 178 rows. So essentially I want to do a 1-many match on the unique identifier, in my example which is responde (essentially respondent id). I thought about maybe doing this in Pandas but it doesn't look like arcpy and pandas are friends yet but I found one of&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;'s suggestions &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/join-dataframe-with-layer/m-p/1109562/highlight/true" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following his instructions I think the arcpy.da.ExtendTable function could work well however, I'm not well versed with numpy and I'm having problems setting up my column names, or as numpy calls them "dtype".&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example ESRI provides is pretty basic with just three values in the array, whereas my csv is 178 rows with quite a lot of data. I have been trying to pass on the dtype names + format with no success.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/extendtable.htm" target="_self"&gt;ESRI Example:&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_0-1667504007537.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55222iC7D5881DA3FF7BFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_0-1667504007537.png" alt="WillemVan_Riet1_0-1667504007537.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is my code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# df = the csv of survey data

df2 = df[['respondent,C,254', 'category', 'value', 'value_cat', 'unique_ID']]
array = df2.to_records()
print(array)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_1-1667504178320.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55225iAB8FC130D51047CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_1-1667504178320.png" alt="WillemVan_Riet1_1-1667504178320.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# apply the dtype attribute
result = df2.dtypes

print("Output:")
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_2-1667504220944.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55227i974ACBC21F456635/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_2-1667504220944.png" alt="WillemVan_Riet1_2-1667504220944.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# try to create a dictionary of my column names this step may be redundant because I have the result variable above

# dts = {'names': ('Unnamed: 0','respondent,C,254','category', 'value', 'value_cat', 'unique_ID'),
#        'formats':(numpy.int64, numpy.object, numpy.object, numpy.object, numpy.object,
#                  numpy.int64)}
array_table = numpy.rec.fromrecords(array, dtype=dts)

# Convert array to a geodatabase table
table = filepath + '\\table_test'
#check that this is a valid filepath
print(table)

arcpy.da.NumPyArrayToTable(array_table, table)

# Append the array to an existing table on responde (shp) to respondent,c,254(csv)
arcpy.da.ExtendTable(cultural_shp, "responde", array, "respondent,C,254")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are my errors - have I not formatted my array correctly?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_3-1667504699617.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55231iAAEDA54ECB562987/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_3-1667504699617.png" alt="WillemVan_Riet1_3-1667504699617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 19:49:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228484#M66018</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2022-11-03T19:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join a dataframe to layer</title>
      <link>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228533#M66019</link>
      <description>&lt;PRE&gt;ExtendTable (in_table, table_match_field, in_array, array_match_field, {append_only})&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Which would be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.da.ExtendTable(cultural_shp, "responde", array, "respondent")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the field names are correct and the featureclass name reference is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 21:18:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228533#M66019</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-11-03T21:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Join a dataframe to layer</title>
      <link>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228596#M66020</link>
      <description>&lt;P&gt;Hi Dan,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your prompt response!&lt;/P&gt;&lt;P&gt;Still getting an error - have I not called the correct fieldname in the array? Or is it some sort of type error for the fieldname? The fieldname I am looking to join to the shapefile is called "respondent,C,254" (name has been copied from the original csv).&lt;/P&gt;&lt;P&gt;Code attached and errors + outputs below in the screenshot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# try to create a dictionary of my column names
dts = {'names': ('Unnamed: 0','respondent,C,254','category', 'value', 'value_cat', 'unique_ID'),
       'formats':(numpy.int64, numpy.object, numpy.object, numpy.object, numpy.object,
                 numpy.int64)}
array_table = numpy.rec.fromrecords(array, dtype=dts)

# Convert array to a geodatabase table
table = filepath + '\\table_test'
arcpy.da.NumPyArrayToTable(array_table, table)

# Append the array to an existing table on responde (shp) to respondent,c,254(csv)
# Dan's comment: ExtendTable (in_table, table_match_field, in_array, array_match_field, {append_only})

arcpy.da.ExtendTable(cultural_shp, "responde", array_table, "respondent,C,254")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_0-1667519776066.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55253iF123B9B86BF513FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_0-1667519776066.png" alt="WillemVan_Riet1_0-1667519776066.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 00:01:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228596#M66020</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2022-11-04T00:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Join a dataframe to layer</title>
      <link>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228602#M66021</link>
      <description>&lt;P&gt;The warning is just that, you don't use numpy.object any more 'O' or object will suffice.&lt;/P&gt;&lt;P&gt;Your field names are horrible, but workable, BUT they won't be able to be used in extendtable because there is punctuation in them.&amp;nbsp; Check the actual data, it should be a list of tuples&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# ---- with horrible field names
# ---- Note the method I use to create dtypes

np.asarray([(1, "test")], dtype=[('Unnamed: 0', 'i8'), ('respondent,C,254', 'O')])
array([(1, 'test')], dtype=[('Unnamed: 0', '&amp;lt;i8'), ('respondent,C,254', 'O')])

# ---- better
np.asarray([(1, "test")], dtype=[('Unnamed', 'i8'), ('respondent', 'O')])
array([(1, 'test')], dtype=[('Unnamed', '&amp;lt;i8'), ('respondent', 'O')])&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Nov 2022 00:49:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-dataframe-to-layer/m-p/1228602#M66021</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-11-04T00:49:58Z</dc:date>
    </item>
  </channel>
</rss>

