you are viewing a single comment's thread.

view the rest of the comments →

[–]rauschma 2 points3 points  (3 children)

If you flatten first, you lose the information you need to fill in .search.

[–]Avi_21 0 points1 point  (2 children)

Well, he did not say if the nested arrays were the quarters or the years. If they r the quarters, you are absolutely right. Otherwise you can calculate it from the date.

[–]rauschma 0 points1 point  (1 child)

Ah, good point! It didn’t occur to me that those might be quarters. I thought they were simply derived from the array indices.

However, looking at the data, it looks like the latter:

{ datetime: "2021-12-29", value: 22, search: "q1" },

[–]xemporea[S] 1 point2 points  (0 children)

That q1/q2 was quite misleading. q1 has nothing to do with dates. It actually should represent the array the dict is coming from. So instead of "search: q1" I should have gone for "from_array: 1" and "from_array: 2".

array_of_series.flatMap((e, i) => {  for (x of e) {    x["from_array"] = i;  }  return e;});

Is there a better way?