# Convert the following list into a Dataset?

Posted 8 months ago
1362 Views
|
13 Replies
|
8 Total Likes
|
 The first row should be treated as a field name instead of data. temp = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Dataset[temp] 
13 Replies
Sort By:
Posted 8 months ago
 temp=AssociationThread[ToString /@ {a, b, c} -> #] & /@ {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Dataset@temp 
Posted 8 months ago
 @Girish Arabale : Sorry, I did not see your answer when I posted mine. Using AssociationThread gives definitely a better solution!
Posted 8 months ago
 @Henrik Schachner : Not at all - the more the merrier!
Posted 8 months ago
 Most likely there is a simpler way, but here is a first attempt : temp = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; keys = ToString /@ First[temp]; values = Rest[temp]; dataset = Dataset[Association /@ (MapThread[Rule, {keys, #}] & /@ values)] which givesRegards -- Henrik
Posted 8 months ago
 If your data is starting in a file (ie CSV or TSV file), you can go direct from file to dataset with SemanticImport[].Regards
Posted 8 months ago
 First of all, thank for your generous help! From everyone's suggestion, I try various methods and observe what is different! temp = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; keys = ToString /@ First@temp; values = Rest@temp; Dataset[Association /@ MapThread[Rule, {keys, #}] & /@ values] Dataset[Association /@ (MapThread[Rule, {keys, #}] & /@ values)] The second dataset can match my imagination of structural data. But if keys = First@temp; keys = First@temp; Dataset[Association /@ MapThread[Rule, {keys, #}] & /@ values] Dataset[Association /@ (MapThread[Rule, {keys, #}] & /@ values)] Although there is no difference in the appearance of the dataset, the actual structure is not the same.{{<|a -> 1|>, <|b -> 2|>, <|c -> 3|>}, {<|a -> 4|>, <|b -> 5|>, <|c -> 6|>}, {<|a -> 7|>, <|b -> 8|>, <|c -> 9|>}}{<|a -> 1, b -> 2, c -> 3|>, <|a -> 4, b -> 5, c -> 6|>, <|a -> 7, b -> 8, c -> 9|>}
Posted 8 months ago
 These two approaches give the same result: AssociationThread[keys -> #] & /@ values (*{<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 4, "b" -> 5, "c" -> 6|>, <|"a" -> 7, "b" -> 8, "c" -> 9|>}*) Association /@ (MapThread[Rule, {keys, #}] & /@ values) (*{<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 4, "b" -> 5, "c" -> 6|>, <|"a" -> 7, "b" -> 8, "c" -> 9|>}*) Three approaches: SemanticImportString[ExportString[temp, "CSV"]] 
Posted 8 months ago
 Given: temp = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Here are some additional styles of solving it. Here we see that we can use <| |> In place of Association[] for a little shorter notation: <|ToString /@ First@temp -> Transpose@Rest@temp // Thread|> (* <|"a" -> {1, 4, 7}, "b" -> {2, 5, 8}, "c" -> {3, 6, 9}|> *) Also if you don't like having too many # and & in your code, you can use the operator form of Map and also Curry which was introduced in version 11.3: Transpose@Rest@temp // Map[Curry[AssociationThread, 2][ToString /@ First@temp]] (*{<|"a" -> 1, "b" -> 4, "c" -> 7|>, <|"a" -> 2, "b" -> 5, "c" -> 8|>, <|"a" -> 3, "b" -> 6, "c" -> 9|>}*) 
Posted 8 months ago
 It's amazing! Different instructions produce different data structures! I am an environmental epidemiology student and mathematica beginner. I would like to use public data to observe the distribution of air pollution concentrations but plagued by a large number of monitoring station coordinates and observations (CSV file). The coordinates and observations of these coordinates and observations are converted to GeoPosition or GeoShothistogram every day. Now that the CSV file has converted to Dataset, and establish a long-term database and the workload reduced. The next step is to convert the station coordinates to GeoPosition. The coordinate data is already known as aqi[[;;,{-2,-1}]]. How to put coordinates into GeoPosition?  aqi = Import[ "http://opendata.epa.gov.tw/ws/Data/AQI/?\$format=csv", {"CSV", "Dataset"}, HeaderLines -> 1]; I have tried the following instructions but it does not work p={#Latitude, #Longitude} & /@ aqi;GeoListPlot[p] 
Posted 8 months ago
 One way of doing I can think of quickly is: p = aqi[All /* Catenate /* (Partition[#, 2] &) /* GeoPosition, {"Latitude", "Longitude"}] which will create GeoPosition arrays. You can generate map: GeoListPlot[p] 
Posted 8 months ago
 If I need to use GeoSmoothHistogram[locs,espec], I want to use GeoPosition and AQI indicator (aqi [[;;, 3]]). What should I do?Is it possible to consider GeoElevationData at the same time?
 pos = Values[Normal[aqi[All, {"Latitude", "Longitude", "AQI"}]]] /. {lat_, long_, aqi_} :> Thread[GeoPosition[{lat, long}] -> aqi]; GeoSmoothHistogram[Association[pos], ColorFunction -> "Rainbow", Mesh -> 20, MeshStyle -> Directive[Opacity[0.085], Blue], GeoBackground -> "StreetMap"] You need to generate GeoElevationData :  ged= GeoElevationData /@(Values[Normal[aqi[All, {"Latitude", "Longitude"}]]] /. {lat_, long_} :> GeoPosition[{lat, long}]) Check with GeoBackground -> "ReliefMap" option in the above plot. Play with GeoElevationData too. Have been just throwing quick solutions while commuting...