I'd like to transform the below dataset array into a different format. Currently, each dictionary in the array has a 'count', 'fruit', and 'first name'. I'd like to create a new dictionary for each distinct first name and values that first name has for each 'fruit' type.
For example, see below for some input data
var input_data = [{"count":1,"fruit":"apple","first_name":"abe"},{"count":1,"fruit":"apple","first_name":"bob"},{"count":10,"fruit":"banana","first_name":"bob"},{"count":5,"fruit":"cherry","first_name":"abe"}]
We know for this dataset that the categories are ['apple', 'banana', 'cherry']
var desired_output =
[{name: 'abe',data:[1,0,5]},
{name: 'bob',data:[1,10,0]}]
groupBy?uniq(map('fruit', data))). UsegroupBywith the.first_nameproperty, thenmapthe values to the desired output elements (selecting the name, mapping every item to its index in the categories array).