I have a data file contains several lines of numbers that separated by "," and I cannot load it correctly with ReadList and Import.
Here is a example:
with data contains "," and "\n", simple ReadList
doesn't work.
ReadList[StringToStream["1099.5,0,-166.79\n1098.4,0,-166.79\n"], Real]
(* {1099.5, $Failed} *)
If we use separators, it works, but if we group the types, it doesn't work.
ReadList[StringToStream["1099.5,0,-166.79\n1098.4,0,-166.79\n"], Real,
RecordSeparators -> {",", "\n"}]
(* {1099.5, 0., -166.79, 1098.4, 0., -166.79} *)
ReadList[StringToStream[
"1099.5,0,-166.79\n1098.4,0,-166.79\n"], {Real, Real, Real},
RecordSeparators -> {",", "\n"}]
(* {$Failed} *)
And Import
cannot import correctly as it treats each line as a string.
Import[StringToStream["1099.5,0,-166.79\n1098.4,0,-166.79\n"], "Table"]
StringQ /@
Flatten@Import[
StringToStream["1099.5,0,-166.79\n1098.4,0,-166.79\n"], "Table"]
(*
{{"1099.5,0,-166.79"}, {"1098.4,0,-166.79"}}
{True, True}
*)
So why they are not working in these cases? And How to make ReadList
and Import
to work without using Partition
etc. after the import?
Version: 9.0 on Mac.
ReadList
needs to haveRecord
instead ofReal
. I think the latter is not very well known, but your question's main focus seems to be on performance with large files. You should focus on that instead. In any case, that would probably make this a dupe of the post that RunnyKine linked to... $\endgroup$