How would you use ReadList
to read a CSV that has both numerical and string data?
Example:
data = "1.2,foo,4.5
6,bar,0.5";
str = StringToStream[data]
ReadList[str, ???]
Close[str]
What if some of the strings include commas?
data = "1.2,\"foo\",4.5
4,\"bar,baz\",0.5";
The desired result is
ImportString[data, "CSV"]
(* {{1.2, "foo", 4.5}, {4, "bar,baz", 0.5}} *)
EDIT:
To explain further, the function I am looking for would be able to do exactly what SemanticImport
does in the following example, but it would perform much better on large data:
data = "x,name,y
1.2,foo,4.5
6,\"bar,baz\",0.5
9,666,0";
SemanticImportString[data, {"Number", "String", "Number"}, "NamedColumns", HeaderLines -> 1]
(* <|"x" -> {1.2`, 6, 9}, "name" -> {"foo", "bar,baz", "666"}, "y" -> {4.5`, 0.5`, 0}|> *)