4
$\begingroup$

The very first example in the Dataset documentation is the following:

dataset = Dataset[{
<|"a" -> 1, "b" -> "x", "c" -> {1}|>,
<|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
<|"a" -> 3, "b" -> "z", "c" -> {3}|>,
<|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,
<|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,
<|"a" -> 6, "b" -> "z", "c" -> {}|>}]

The third column of this dataset contains Lists. I would like to create a file that I can read (e.g. using SemanticImport) and that will parsed into this format.

An example for a String that does not work:

datatest = SemanticImportString["a\tb\tc\1\tx\t{1}\n"]

Here the column labeled "c" becomes the String "{1}".

Similarly,

datatest = SemanticImportString["a\tb\tc\n1\tx\t{1}\n", {"String", "String", "List"}]

puts the String "{1}" into a List: {"{1}"}.

Since the Dataset format is touted as a way to work with hierarchical data sets I assume there must be some convenient way to actually read in a hierarchical data set? Many thanks!

$\endgroup$

1 Answer 1

4
$\begingroup$

From what I can tell you want {1} in your string to be read as a Mathematica expression, i.e. read as a List. I believe you may therefore use the type "Expression":

SemanticImportString["a\tb\tc\n1\tx\t{1}\n", {"String", "String", "Expression"}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.