(total, data, replace=True, accounting_column=None,
                max_iterations=50, prob_column=None, return_status=False)
Samples and returns rows from a data frame while matching a desired control total. The total may
    represent a simple row count or may attempt to match a sum/quantity from an accounting column.

    Parameters
    ----------
    total : int
        The control total the sampled rows will attempt to match.
    data: pandas.DataFrame
        Table to sample from.
    replace: bool, optional, default True
        Indicates if sampling with or without replacement.
    accounting_column: string, optional
        Name of column with accounting totals/quantities to apply towards the control.
        If not provided then row counts will be used for accounting.
    max_iterations: int, optional, default 50
        When using an accounting attribute, the maximum number of sampling iterations
        that will be applied. Only applicable when sampling with replacement.
    prob_column: string, optional, default None
        If provided, name of the column in the data frame to provide probabilities
        or weights. If not provided, the sampling is random.
    return_status: bool, optional, default True
        If True, will also return a bool indicating if the total was matched exactly.

    Returns
    -------
    sample_rows : pandas.DataFrame
        Table containing the sample.
    matched: bool
        If return_status is True, returns True if total is matched exactly.
Samples and returns rows from a data frame while matching a desired control total. The total may
    represent a simple row count or may attempt to match a sum/quantity from an accounting column.
Samples and returns rows from a data frame while matching a desired control total . The total may represent a simple row count or may attempt to match a sum / quantity from an accounting column .
def sample_rows(total, data, replace=True, accounting_column=None,
                max_iterations=50, prob_column=None, return_status=False):
    """
    Samples and returns rows from a data frame while matching a desired control total. The total may
    represent a simple row count or may attempt to match a sum/quantity from an accounting column.

    Parameters
    ----------
    total : int
        The control total the sampled rows will attempt to match.
    data: pandas.DataFrame
        Table to sample from.
    replace: bool, optional, default True
        Indicates if sampling with or without replacement.
    accounting_column: string, optional
        Name of column with accounting totals/quantities to apply towards the control.
        If not provided then row counts will be used for accounting.
    max_iterations: int, optional, default 50
        When using an accounting attribute, the maximum number of sampling iterations
        that will be applied. Only applicable when sampling with replacement.
    prob_column: string, optional, default None
        If provided, name of the column in the data frame to provide probabilities
        or weights. If not provided, the sampling is random.
    return_status: bool, optional, default True
        If True, will also return a bool indicating if the total was matched exactly.

    Returns
    -------
    sample_rows : pandas.DataFrame
        Table containing the sample.
    matched: bool
        If return_status is True, returns True if total is matched exactly.

    """
    if not data.index.is_unique:
        raise ValueError('Data must have a unique index')

    # simplest case, just return n random rows
    if accounting_column is None:
        if replace is False and total > len(data.index.values):
            raise ValueError('Control total exceeds the available samples')
        p = get_probs(prob_column)
        rows = data.loc[np.random.choice(
            data.index.values, int(total), replace=replace, p=p)].copy()
        matched = True

    # sample with accounting
    else:
        if replace:
            rows, matched = accounting_sample_replace(
                total, data, accounting_column, prob_column, max_iterations)
        else:
            rows, matched = accounting_sample_no_replace(
                total, data, accounting_column, prob_column)

    # return the results
    if return_status:
        return rows, matched
    else:
        return rows
def sample_rows ( total , data , replace = True , accounting_column = None , max_iterations = 50 , prob_column = None , return_status = False ) : if not data . index . is_unique : raise ValueError ( 'Data must have a unique index' ) # simplest case, just return n random rows if accounting_column is None : if replace is False and total > len ( data . index . values ) : raise ValueError ( 'Control total exceeds the available samples' ) p = get_probs ( prob_column ) rows = data . loc [ np . random . choice ( data . index . values , int ( total ) , replace = replace , p = p ) ] . copy ( ) matched = True # sample with accounting else : if replace : rows , matched = accounting_sample_replace ( total , data , accounting_column , prob_column , max_iterations ) else : rows , matched = accounting_sample_no_replace ( total , data , accounting_column , prob_column ) # return the results if return_status : return rows , matched else : return rows