def group_sums(x, group, use_bincount=True):
    x = np.asarray(x)
    if x.ndim == 1:
        x = x[:, None]
    elif x.ndim > 2 and use_bincount:
        raise ValueError('not implemented yet')

    if use_bincount:

        # re-label groups or bincount takes too much memory
        if np.max(group) > 2 * x.shape[0]:
            group = pd.factorize(group)[0]

        return np.array([np.bincount(group, weights=x[:, col])
                         for col in range(x.shape[1])])
    else:
        uniques = np.unique(group)
        result = np.zeros([len(uniques)] + list(x.shape[1:]))
        for ii, cat in enumerate(uniques):
            result[ii] = x[g == cat].sum(0)
        return result
Display count of total words and selected words in a dialog box.
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tools/grouputils.py/group_sums--crossover with--dataset/ETHPy150Open cpbotha/nvpy/nvpy/view.py/View.word_count