datamash -t, --header-in -s -g 3 mean 4 < data.csv
Sort groups, then compute mean of column 4 by column 3
Adding -s (sort) orders the group-by output by the grouping key instead of first-seen order. The sort applies to the grouping column, so group labels appear alphabetically. Compare this with the unsorted grouped mean to see the difference in row order. Pipe the output through sort -k2 -nr if you want groups ranked by their mean instead.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.