Select to view content in your preferred language

Csv data has cells with comma separated values

1091
2
Jump to solution
01-10-2023 05:42 PM
Labels (3)
Suedietrich
Occasional Contributor

Hello,

I wonder if someone can help me here. I have a csv table cells with comma separated values. I need to split those comma separated values into new rows and populate the corresponding field by dividing the dollar amount to the number of newly created rows

image.jpg

 so I am trying to create something like this:

image.jpg

 I haven’t included the dataset as it is huge. I know I can accomplish this in excel, but I want to automate the process with a larger dataset update in ArcGIS Pro. Thank you all in advance!

 

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Alum

Just one approach, this can be done using python expressions in the Python window. You can copy and paste the results into a new file to read it in as a table.

 

with arcpy.da.SearchCursor("file.csv") as rows:
  for row in rows:
    ids = row[0].split(",")
    val = float(row[1])
    valpart = val / len(ids)
    for k in ids:
      print(k, valpart)

 

    

View solution in original post

2 Replies
curtvprice
MVP Alum

Just one approach, this can be done using python expressions in the Python window. You can copy and paste the results into a new file to read it in as a table.

 

with arcpy.da.SearchCursor("file.csv") as rows:
  for row in rows:
    ids = row[0].split(",")
    val = float(row[1])
    valpart = val / len(ids)
    for k in ids:
      print(k, valpart)

 

    

Suedietrich
Occasional Contributor

Many thanks!!

0 Kudos