import collections


def _sum_by_feature_col_name_and_sort(names, vals):
  """Group by feature column names, sum values, and sort by absolute value."""
  sum_by_dict = {}
  # Groupby and sum.
  for name, val in zip(names, vals):
    sum_by_dict[name] = sum_by_dict.setdefault(name, 0) + val
  # Then sort.
  sorted_sum_by = sorted(
      sum_by_dict.items(), key=lambda tup: abs(tup[1]), reverse=True)
  return collections.OrderedDict(sorted_sum_by)