# Importing table with symbolic and numerical rows

Consider generated numerical data with added symbolical row:

data = RandomReal[1, {10, 5}]
data2 = Join[{{"Value 1", "Value 2", "Value 3", "Value 4",
"Value 5"}}, data]


Now, consider we made export and then want to import the data:

SetDirectory[NotebookDirectory[]];
Export["data2.dat", data2]
data3 = Import["data2.dat"]


The text column which is displayed correctly in initial data2 in data3 is displayed incorrectly. Namely, the spaces are replaced by commas, which results in different length of row with symbols and row with numbers.

How to force Mathematica to import the file correctly? I thought that "" would help, but they didn't...

Probably it's best to explicitly name the format, in this case "TSV". as the separation between fields are tabular characters (ToCharacterCode["\t"] -> 9).

InputForm@Import["data2.dat", "TSV"]


The data as saved in the file "data2.dat" is "TSV" and not "CSV"

You could compress the sublist with strings:

Export["data2.dat", MapAt[Compress, data2, 1]]
data3 = MapAt[Uncompress@*First, Import["data2.dat"], 1]
data3 === data2


True

Export["d:\\2018\\data2.dat", data2 ]
data3 = Import["d:\\2018\\data2.dat", "TSV"]
Simplify[data2==data3]
(*True*)


works fine!

• But the data, as saved, is "TSV" and not "CSV". – rhermans Jul 27 '18 at 14:42
• Where "TSV" appears? data and data2 are comma separated lists, so I export/import as "CSV"! – Ulrich Neumann Jul 27 '18 at 14:50
• The data in the OP is "TSV". – rhermans Jul 27 '18 at 14:50
• data2 =={{"Value 1", "Value 2", "Value 3", "Value 4", "Value 5"}, {0.0348347, 0.0162931, 0.26708, 0.4453, 0.910656},...} – Ulrich Neumann Jul 27 '18 at 14:53
• Now I got it!!! My answer is edited. – Ulrich Neumann Jul 27 '18 at 14:56