Table_to_table reads text as a floating number(scientific notation).

386
2
Jump to solution
10-18-2021 09:49 PM
Jae_Jeon
New Contributor II

Hello, 

 I tried to read a txt file(attached) with 25 length number-like text-type field(‘num2’field in the txt file, e.g. 3123412452000123) in a code below.

Jae_Jeon_0-1634618818415.png

 

ws = path to default.gdb.. 
csvpath = path to 'sample_q.txt' ..
gj_db.to_csv(csvpath, index=False, encoding='utf-8')
# define the 'num2' field as a text-type field.
fm = Create_Fieldmap(target_feature = csvpath)

build_db = arcpy.conversion.TableToTable(csvpath, ws, "t2t_table")

 

 

But, when I use "arcpy.conversion.TableToTable" with fieldmap(to define the field as a text-type field) the line causes error that 'ERROR 001156: Failed on input OID 1, could not write value '2.91101010010084E+24' to output field ..'.

It’s because  TableToTable read ‘num2’ value as a floating number(scientific notation). 

Jae_Jeon_1-1634618818405.png

 

How can I read the value as text type value?

Thanks in advance for any help! 

 

Jae,

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DominicRoberge2
Occasional Contributor

Hey Jae

I think if you create a schema.ini file in the same folder as your txt (csv) file that should work. I just tested it and it's working for me. Good luck!

 

[tab2tab2.csv]
Format=CSVDelimited
ColNameHeader=True
Col2=num1 Text Width 30
Col3=num2 Text Width 30

View solution in original post

0 Kudos
2 Replies
DominicRoberge2
Occasional Contributor

Hey Jae

I think if you create a schema.ini file in the same folder as your txt (csv) file that should work. I just tested it and it's working for me. Good luck!

 

[tab2tab2.csv]
Format=CSVDelimited
ColNameHeader=True
Col2=num1 Text Width 30
Col3=num2 Text Width 30

View solution in original post

0 Kudos
Jae_Jeon
New Contributor II

It solved the issue, though need to make 'schema.ini' file.  (thought there might be an environment setting to not write it as a float in scientific notation)

Thank you Dominic,

 

0 Kudos