2
$\begingroup$

I have a huge CSV data, with the format like this:

"5";"8";"2803";
"";"6";"2793";

I import the data with this code:

Import["data.csv", "Table", "FieldSeparators" -> ";"];

The problem is: Due to the empty string "" the table structure is broken: the cell is removed. To fix that, I need to manually edit the file. I replace the empty String "" with anything like "0":

"5";"8";"2803";
"0";"6";"2793";

Is there any option to deal with this? To consider "" as the real element?

$\endgroup$
6
$\begingroup$

Option "RepeatedSeparators" -> False solves the problem:

file = "\"5\";\"8\";\"2803\";
\"\";\"6\";\"2793\";";

ImportString[file, "Table", "FieldSeparators" -> ";", "RepeatedSeparators" -> False]
{{5, 8, 2803, ""}, {"", 6, 2793, ""}}

Although I would consider the default behavior as a bug: the element "" (substring "\"\"" of the whole file) shouldn't be interpreted as an absence of a field, it is just an empty string "" which is a perfectly valid field!

$\endgroup$
  • $\begingroup$ Thank you Alexey! $\endgroup$ – Nam Nguyen Feb 1 '18 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.