Select to view content in your preferred language

Need to automate the reformatting of tables

3873
15
01-26-2023 06:42 AM
Labels (2)
BarryG
by
Occasional Contributor

I would like to automate a process to copy, reformat, and join tables to a feature class.  I have an idea of how to implement the process in Modelbuilder, all except reformatting the tables (attached snapshots).  The original tables are Pipe delimited.  The attached files are the final result of reformatting them in Microsoft Excel.  

Does anyone know of geoprocessing tools that can be used to reformat the original tables into a usable format as such?

 

Thanks,

Barry

0 Kudos
15 Replies
RhettZufelt
MVP Notable Contributor

Maybe something weird with your input table as the replacement of pipes with delimeter should still keep the vacant cells.  Hard to tell with just a pic of it.

I did my best to capture the first part, including empty cells and spaces, though I did rename Pin1.

However, had a little brain fog on this end I guess.  Comma separated values is NOT the way to go when you have commas in your data as it sees them as delimeters also.  So, any row that has a city,state in it will add extra columns.

Looks like if you make it a tab separated file, should work for you:

infile = r"C:\folder\tmp\_testPipe"
delimiter = '\t'
f = open(infile,'r')
filedata = f.read()
f.close()
newfile = infile + ".txt"
newdata = filedata.replace("|",delimiter)
f = open(newfile,'w')
f.write(newdata)
f.close()

 

Input data:

RhettZufelt_5-1674836496829.png

 

RhettZufelt_6-1674836530601.png

Then, in Excel:

RhettZufelt_7-1674836570682.png

ArcMap:

RhettZufelt_10-1674836740711.png

Pro:

RhettZufelt_9-1674836590484.png

R_

 

0 Kudos
BarryG
by
Occasional Contributor

Hmmm, when I ran the script this time, it only separated out the last column (see attached).

 Thank you so much for helping!

infile = r"C:\TEMP\PRC\PARCELADDRESSLIST.csv"
delimiter = '\t'
f = open(infile,'r')
filedata = f.read()
f.close()
newfile = infile + ".txt"
newdata = filedata.replace("|",delimiter)
f = open(newfile,'w')
f.write(newdata)
f.close()
0 Kudos
RhettZufelt
MVP Notable Contributor

This was written for a Pipe "|" delimited input file.  looks like yours is csv?  And should output to a *.txt file.

Can you post the original pipe file (like you did with these csv's) instead of a pic of them?  Would make it easier to see what is going on.

R_

0 Kudos
BarryG
by
Occasional Contributor

Attached are the original data dump files. Thanks!

0 Kudos
RhettZufelt
MVP Notable Contributor

Dowloaded the files, Renamed Pin to Pin2, also in the PRCDATA, had to rename the second BLDG NO to BLDG NO2 (surprised there are not more issues as Arc generally doesn't like spaces in field names) as there were errors trying to bring a table into Pro with duplicate field names.

Kept them as pipe delimted file with no extention as supplied:

RhettZufelt_11-1674860028157.png

 

Ran the code:

RhettZufelt_2-1674859631299.png

which saved the new files with .txt extention:

RhettZufelt_3-1674859654558.png

Open the new .txt files in Excel:

RhettZufelt_4-1674859725274.png

RhettZufelt_5-1674859755731.png

In ArcMap:

RhettZufelt_6-1674859788363.png

RhettZufelt_8-1674859849908.png

In Pro:

RhettZufelt_9-1674859865025.png

RhettZufelt_10-1674859881707.png

Only issues it had were the duplicate column names Pin and BLDG NO.

R_

 

 

 

 

 

 

0 Kudos
BarryG
by
Occasional Contributor

Strangely, I tried to recreate the same and still doesn't work on my end. It is still not fully separating the fields/values correctly.

 

Thank you.

Barry

0 Kudos