Quantcast
Channel: Better way to create a Dataset? - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by creidhne for Better way to create a Dataset?

$
0
0

This common data format, where the first row of data has column names, and the following rows are values, is easy to convert to a dataset with AssociationThread.

list = {{"date", "time", "volume"},    {a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}};ds = Dataset[AssociationThread[First@list, #] & /@ Rest@list]

Often, data from comma-separated values and other tabular file formats is arranged in the same way. For example, it's easy to import a CSV file to a dataset with the HeaderLines option. This avoids the need to convert an imported array.

ds = Import["file.csv", "Dataset", HeaderLines -> 1]

Related: How to display properly Dataset with index column?


Viewing all articles
Browse latest Browse all 3