# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.35563522577285767, "perplexity": 1298.797183156365}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-49/segments/1669446710972.37/warc/CC-MAIN-20221204104311-20221204134311-00425.warc.gz"}