# how to import data with 'arbitary' format?

When I want to import data (.txt or .dat) for plotting, I can just use the Import. Problem is that, sometimes the data in the files are separated by comma, sometimes they don't. Sometimes they are arranged in columns nicely, sometimes they are just in one line. My usual approach is to 'beautify' the data manually, by making sure that each pair of data occupies one line, and the coordinates are separated by the tab key without any comma. This works for a small number of data, and will be impossible for large amount of data.

So my question is, are they any ways to import data regardless of how they are arranged in the data file?

Import and SemanticImport can handle many different formats, and each has several options to customize the import.

For a start, check out Table, TSV and CSV.

Look at documented "Table" options such as "FieldSeparators", "IgnoreEmptyLines", "RepeatedSeparators", "HeaderLines", etc. These give you quite a but of flexibility. It is possible to simultaneously allow multiple different field and record separators, e.g. let either tab or comma separate entries within the same file.

SemanticImport can additionally take a type specification for each column you are importing. This helps with certain data formats. It also has a "Delimiters" option. Its return type can be controlled using its third argument (format), which is described in the Details section of its documentation page. SemanticImport is unfortunately slower than Import.

There is also Read and ReadList. ReadList is very fast, takes type specifications and allows specifying the RecordSeparators.

• SemanticImport actually manages to load the data in a nice table format, but is it possible to convert it to a matrix? The main problem I am having is that if I use Import, very often it can represents the data in matrix form Sep 1, 2016 at 10:40
• @Physicist Ah, I assume you mean that it returns a Dataset by default. Please look up Dataset. Please check under the Details section of the SemanticImport documentation where it is explained how to use its third argument ("form") to choose a return format (e.g. list of rows like Import). Sep 1, 2016 at 10:42
• @Physicist You can use Normal to convert a Dataset to nested lists and associations. It may actually be ds[All, Values] or similar what you need, depending on the type of Dataset. But better just use the third argument of SemanticImport. Sep 1, 2016 at 10:51
• Normal works perfectly for me in this case. thx Sep 1, 2016 at 10:57