def _remove_rows_by_count(df, amount, count):
    """
    Remove rows from a table so that the sum of the values in column
    `count` is reduced by `amount`.

    Parameters
    ----------
    df : pandas.DataFrame
    amount : float
        Amount by which to decrease sum of `count` column.
    count : str
        Name of column to sum for accounting.

    Returns
    -------
    new_df : pandas.DataFrame

    """
    if amount == 0:
        return df.copy()

    sort_count = df[count].sort_values(ascending=False, inplace=False)
    sort_count = sort_count[(sort_count <= amount) & (sort_count != 0)]

    to_remove = []

    for k, v in sort_count.iteritems():
        if v <= amount:
            to_remove.append(k)
            amount -= v

        if amount == 0:
            break

    to_keep = df.index.difference(to_remove)

    return df.loc[to_keep]