What is the opposite of a groupby or Bag sort? Is there a specific term used for an operation like this in programming lingo?
As in an aggregation in which items are sorted by family and summed by counting them, but in reverse.
Examples Python:
>>> grouped = {"a": 2,
... "b": 1,
... "c": 3}
>>> ungrouped = [[key]*grouped[key] for key in grouped.keys()]
>>> ungrouped
[['a', 'a'], ['c', 'c', 'c'], ['b']]
>>>
Or MySql:
SELECT thing,COUNT(*) FROM a.table WHERE thing='isafamilygroupbag';
Or Bash:
declare -A grouped
grouped=( [a]=2 [b]=1 [c]=3 )
ungrouped=()
for k in "${!grouped[@]}"; do
v=$(echo "${grouped[$k]}")
for count in $(seq 1 ${v[0]}); do
ungrouped+=" $k "
done
done
echo "${ungrouped[@]}"
I am not so much interested in the implementation of doing such a process, but what it is called.
Similar:
- Is there an "ungroup by" operation opposite to .groupby in pandas?
- Is there in pandas operation complementary (opposite) to groupby?
update
Also related: