<?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 Re: Batch Geocode Result write to file Scrambled out of order in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/batch-geocode-result-write-to-file-scrambled-out/m-p/1417546#M9966</link>
    <description>&lt;LI-CODE lang="python"&gt;# A function that extracts items from a list
def address_extractor_roof(api_response_list)
    """
    This function extracts relevant information
    from API response.
    """
    # Create an empty dataframe
    extracted_df = pd.DataFrame()

    # Create an empty list
    latitude, longitude, match, score, addr_type = [],[],[],[],[]
   
    # Create a FOR loop to extract the data
    for api_response in api_response_list:
        try:
            # Extract the variables
            latitude.append(api_response[0]['attributes']['DisplayY'])
            longitude.append(api_response[0]['attributes']['DisplayX'])
            match.append(api_response[0]['attributes']['Status'])
            score.append(api_response[0]['attributes']['Score'])
            addr_type.append(api_response[0]['attributes']['Addr_type'])
        except IndexError:
            print(api_response)
   
    # Append columns to form a dataframe
    extracted_df['latitude'] = latitude
    extracted_df['longitude'] = longitude
    extracted_df['match'] = match
    extracted_df['score'] = score
    extracted_df['addr_type'] = addr_type
   

    # Return the dataframe
    return extracted_df&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 01 May 2024 16:17:29 GMT</pubDate>
    <dc:creator>PrinceOseiBonsu</dc:creator>
    <dc:date>2024-05-01T16:17:29Z</dc:date>
    <item>
      <title>Batch Geocode Result write to file Scrambled out of order</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/batch-geocode-result-write-to-file-scrambled-out/m-p/1416224#M9954</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm trying to do a batch geocode, then write the results to a CSV file with the lat and long column added on.&lt;/P&gt;&lt;P&gt;Everything works fine, but the final written result to the CSV file is mixed up causing different XY values to be added to the wrong address.&lt;/P&gt;&lt;P&gt;I'm following this YT video: &lt;A href="https://www.youtube.com/watch?v=ZbOD8mrX3c8" target="_blank" rel="noopener"&gt;https://www.youtube.com/watch?v=ZbOD8mrX3c8&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Please see attached code and screenshots.&amp;nbsp; Python 3.9.16 shipped with ArcPro 3.2&lt;/P&gt;&lt;P&gt;Any help or idea as to why this is happening?&amp;nbsp; Thanks in advanced.&lt;/P&gt;&lt;P&gt;Python Terminal results&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="victhomas_0-1714203868113.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/102379i45C107312AD33675/image-size/medium?v=v2&amp;amp;px=400" role="button" title="victhomas_0-1714203868113.png" alt="victhomas_0-1714203868113.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;CSV file output result - does not match what's in the terminal&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="victhomas_1-1714203944730.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/102380i7AE15901B0D4A692/image-size/medium?v=v2&amp;amp;px=400" role="button" title="victhomas_1-1714203944730.png" alt="victhomas_1-1714203944730.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis.gis import GIS
from arcgis.geocoding import get_geocoders, batch_geocode, geocode, Geocoder

gis = GIS("https://arcgis.com","user","password")
print(gis.properties.user.role)

GeocodeURL = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"
orgGeoCoder = Geocoder(GeocodeURL, gis)

input_file = "C:\\Users\\temp\\coffeeshops.csv"
output_file = "C:\\Users\\temp\\coffeeshops_coded.csv"
address_column_name = "Address"
data = pd.read_csv(input_file, encoding='utf8')

print(data.head(20))

if address_column_name not in data.columns:
    raise ValueError("Missing Address column in input data")

addresses = (data[address_column_name]+", " + data['City'] + ", " + data['State']).tolist()

results = batch_geocode(addresses=addresses, geocoder=orgGeoCoder)

latcoords = []
longcoords = []
for coordinates in results:
    print("Score "+ str(coordinates['score']) + " : " + coordinates['address'] + " " + str(coordinates['location']))
    latitude = coordinates['location']['y']
    longitude = coordinates['location']['x']
    latcoords.append(latitude)
    longcoords.append(longitude)

data['Long']=longcoords
data['Lat']=latcoords

pd.DataFrame(data).to_csv(output_file, encoding='utf8')

print("done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 07:54:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/batch-geocode-result-write-to-file-scrambled-out/m-p/1416224#M9954</guid>
      <dc:creator>victhomas</dc:creator>
      <dc:date>2024-04-27T07:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Geocode Result write to file Scrambled out of order</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/batch-geocode-result-write-to-file-scrambled-out/m-p/1417546#M9966</link>
      <description>&lt;LI-CODE lang="python"&gt;# A function that extracts items from a list
def address_extractor_roof(api_response_list)
    """
    This function extracts relevant information
    from API response.
    """
    # Create an empty dataframe
    extracted_df = pd.DataFrame()

    # Create an empty list
    latitude, longitude, match, score, addr_type = [],[],[],[],[]
   
    # Create a FOR loop to extract the data
    for api_response in api_response_list:
        try:
            # Extract the variables
            latitude.append(api_response[0]['attributes']['DisplayY'])
            longitude.append(api_response[0]['attributes']['DisplayX'])
            match.append(api_response[0]['attributes']['Status'])
            score.append(api_response[0]['attributes']['Score'])
            addr_type.append(api_response[0]['attributes']['Addr_type'])
        except IndexError:
            print(api_response)
   
    # Append columns to form a dataframe
    extracted_df['latitude'] = latitude
    extracted_df['longitude'] = longitude
    extracted_df['match'] = match
    extracted_df['score'] = score
    extracted_df['addr_type'] = addr_type
   

    # Return the dataframe
    return extracted_df&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 May 2024 16:17:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/batch-geocode-result-write-to-file-scrambled-out/m-p/1417546#M9966</guid>
      <dc:creator>PrinceOseiBonsu</dc:creator>
      <dc:date>2024-05-01T16:17:29Z</dc:date>
    </item>
  </channel>
</rss>

