Creating workforce assignments using arcgis api for python

975
3
09-09-2021 07:23 AM
SpheleleNtilane7
New Contributor

My name is Sphe from South Africa and I am relatively new to programming. I am trying to create workforce assignments using Arcgis Api for python but I am failing.  I have tried using these scripts from workforce-scripts/2 - Importing Assignments.ipynb at master · Esri/workforce-scripts (github.com) but I'm still not winning. I get a Key error when i  try to import my assignments from a csv.

if tolerance is not None:

KeyError: 'Location'

 This is the part of the code that is giving me a major headache:

csv_file = pd.read_csv('C:/Users/sphelele.ntilane/Desktop/Book.csv')
csv_file

 

csv_file_assignments = []

for index, row in csv_file.iterrows():
geometry = geocode(f"{row['Location']} {row['Suburb']}", out_sr=3857)[0]["location"]
csv_file_assignments.append(
workforce.Assignment(
project,
geometry=geometry,
location=row["Location"],
description=row["Description"],
priority=row["Priority"],
work_order_id=row["Work Order ID"],
assignment_type="No_Water",
status="unassigned"
)
)
project.assignments.batch_add(assignments)

Whoever can assist please do

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor

@SpheleleNtilane7 can you provide a sample of the CSV your script is querying?

0 Kudos
SpheleleNtilane7
New Contributor

Hi Jake

Its seems pandas in Jupyter notebook  does not recognize columns in my csv and just groups all columns into one.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

It looks like your CSV is formatted to use a semi-colon (;) as the delimeter.  Pandas defaults to using a comma (,).  When reading the CSV, specify the delimeter parameter.  Ex:

 

csv_file = pd.read_csv('C:/Users/sphelele.ntilane/Desktop/Book.csv', delimiter=';')
0 Kudos