udibehar
(Ehud Behar)
1
I have the following csv file (attached file)
ch1;ch2;ch3
10;1;100
20;2;200
30;3;300
40;4;400
50;5;500
I want to import it to Mathematica as a Dataset, and I tried the following command:
Import["ref.csv", "Dataset", "FieldSeparators" -> {";"}]
which gave me the following:
whereas what I want is obviously
Any help?
ref.csv (63 Bytes)
Hi Ehud,
The attached “ref.csv” is comma separated, not ;. Anyway “FieldSeparators” is not an option for CSV import. Workaround
Import["path/to/file", "Table", "FieldSeparators" -> {";"}] // Dataset
gdelfino
(Gustavo Delfino)
3
I opened the file in a text editor and found that your file has commas, not semi colons.
udibehar
(Ehud Behar)
4
You are right. Sorry.
I updated the csv file attached.
stevef
(Steve Flanagan)
5
A string split on each line would also do the trick:
Dataset[Flatten[StringSplit[#, ";"]] & /@ Import["path/to/file"]]
If it’s a larger dataset, then I would suggest using BinaryReadList to make it import more quickly:
Dataset[StringSplit[#, ";"] & /@
StringSplit[
FromCharacterCode[BinaryReadList["path/to/file"], "UTF-8"],
"\r\n"]]