Message Boards Message Boards

2
|
5149 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Mathematica 12 deletes the blank spaces when I import a TSV-File?

Posted 3 years ago

Dear all, I have upgraded from Mathematica Version 10 to 12. Up to now I imported my datasets from a textfile using

Import[fn, "TSV", "Numeric" -> False]

Im Mathematica 10 my tab separated data was nicely separated as you can see in the following InputForm:

{" 2e54295", "       0"}

In Mathematica 12 the preceding blanks, which are important for a checksum, are missing.

{"2e54295", "0"}

I haven't found a related option. Any suggestions?

Maybe you can directly share an example using the following ImportString as starting point

ImportString[" 2e54295\t       0", "TSV", 
  "Numeric" -> False] // InputForm
POSTED BY: Thorsten Gerloff
3 Replies

Thank you both for the quick responses with suggested solutions and explanations.

I will then adjust my evaluations and pay attention to the speeds. The data sets are many MB in size and consist of decimal numbers, hexadecimal numbers and strings and must be converted accordingly.

The thread can be closed.

POSTED BY: Thorsten Gerloff
Posted 3 years ago

Several bugs were fixed in the CSV and TSV formats and the performance was dramatically improved between version 10 and 12. Leading and trailing spaces that are part of non-quoted fields are ignored as this is by far the most common behavior and expected by many applications. The old implementation of CSV was based on the Table format, so you can get that behavior bug for bug by doing:

ImportString[" 2e54295\t       0", "Table", "Numeric" -> False, "FieldSeparators" -> "\t"] // InputForm

If it is possible to rewrite your CSV files to quote these fields, then you can still use the CSV format and preserve spacing:

ImportString["\" 2e54295\"\t\"       0\"", "TSV", "Numeric" -> False] // InputForm
POSTED BY: Sean Cheren
POSTED BY: Carl Verdon
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract