bucketplot.py
def custom_width(df, bucket_var, width, boundary=0, first_break=None, last_break=None):
    """
    Assign each row of `df` to a bucket by dividing the range of the 
    `bucket_var` column into `n_bins` number of equal width intervals.
    
    df: DataFrame
    bucket_var: Name of the column of df to use for dividing.
    width: Positive width of the buckets
    boundary: Edge of one of the buckets, if the data extended that far
    first_break: All values below this (if any) are grouped into one bucket
    last_break: All values above this (if any) are grouped into one bucket
    
    Returns: df with the additional `bucket` column 
        The `bucket` column is Categorical data type consisting of Intervals
        that partition the interval from just below min(bucket_var) to 
        max(bucket_var).
    """
    var_min, var_max = df[bucket_var].min(), df[bucket_var].max()
    extended_min = var_min - 0.001 * np.min([(var_max - var_min), width])

    # Set bucket edges
    start = np.floor((extended_min - boundary) / width) * width + boundary
    stop = np.ceil((var_max - boundary) / width) * width + boundary
    num = int((stop - start) / width) + 1
    breaks_all = np.array([
        extended_min,
        *np.linspace(start, stop, num)[1:-1],
        var_max,
    ])
    
    # Clip lower and upper buckets
    breaks_clipped = breaks_all
    if first_break is not None or last_break is not None:
        breaks_clipped = np.unique(np.array([
            breaks_all.min(),
            *np.clip(breaks_all, first_break, last_break),
            breaks_all.max(),
        ]))
    breaks_clipped
    
    df_w_buckets = df.assign(
        bucket=lambda df: pd.cut(df[bucket_var], bins=breaks_clipped)
    )
    return(df_w_buckets)

    Assign each row of `df` to a bucket by dividing the range of the 
    `bucket_var` column into `n_bins` number of equal width intervals.
    
    df: DataFrame
    bucket_var: Name of the column of df to use for dividing.
    width: Positive width of the buckets
    boundary: Edge of one of the buckets, if the data extended that far
    first_break: All values below this (if any) are grouped into one bucket
    last_break: All values above this (if any) are grouped into one bucket
    
    Returns: df with the additional `bucket` column 
        The `bucket` column is Categorical data type consisting of Intervals
        that partition the interval from just below min(bucket_var) to 
        max(bucket_var).
    


DataFrame
bucket_var: Name of the column of df to use for dividing.
width: Positive width of the buckets
boundary: Edge of one of the buckets, if the data extended that far
first_break: All values below this (if any) are grouped into one bucket
last_break: All values above this (if any) are grouped into one bucket

df with the additional `bucket` column
The `bucket` column is Categorical data type consisting of Intervals
that partition the interval from just below min(bucket_var) to
max(bucket_var).
DataFrame bucket_var : Name of the column of df to use for dividing . width : Positive width of the buckets boundary : Edge of one of the buckets if the data extended that far first_break : All values below this ( if any ) are grouped into one bucket last_break : All values above this ( if any ) are grouped into one bucket df with the additional ` bucket ` column The ` bucket ` column is Categorical data type consisting of Intervals that partition the interval from just below min ( bucket_var ) to max ( bucket_var ) .
def custom_width(df, bucket_var, width, boundary=0, first_break=None, last_break=None):
    var_min, var_max = df[bucket_var].min(), df[bucket_var].max()
    extended_min = var_min - 0.001 * np.min([(var_max - var_min), width])
    start = np.floor((extended_min - boundary) / width) * width + boundary
    stop = np.ceil((var_max - boundary) / width) * width + boundary
    num = int((stop - start) / width) + 1
    breaks_all = np.array([
        extended_min,
        *np.linspace(start, stop, num)[1:-1],
        var_max,
    ])
    breaks_clipped = breaks_all
    if first_break is not None or last_break is not None:
        breaks_clipped = np.unique(np.array([
            breaks_all.min(),
            *np.clip(breaks_all, first_break, last_break),
            breaks_all.max(),
        ]))
    breaks_clipped
    df_w_buckets = df.assign(
        bucket=lambda df: pd.cut(df[bucket_var], bins=breaks_clipped)
    )
    return(df_w_buckets)
def custom_width ( df , bucket_var , width , boundary = 0 , first_break = None , last_break = None ) : var_min , var_max = df [ bucket_var ] . min ( ) , df [ bucket_var ] . max ( ) extended_min = var_min - 0.001 * np . min ( [ ( var_max - var_min ) , width ] ) start = np . floor ( ( extended_min - boundary ) / width ) * width + boundary stop = np . ceil ( ( var_max - boundary ) / width ) * width + boundary num = int ( ( stop - start ) / width ) + 1 breaks_all = np . array ( [ extended_min , * np . linspace ( start , stop , num ) [ 1 : - 1 ] , var_max , ] ) breaks_clipped = breaks_all if first_break is not None or last_break is not None : breaks_clipped = np . unique ( np . array ( [ breaks_all . min ( ) , * np . clip ( breaks_all , first_break , last_break ) , breaks_all . max ( ) , ] ) ) breaks_clipped df_w_buckets = df . assign ( bucket = lambda df : pd . cut ( df [ bucket_var ] , bins = breaks_clipped ) ) return ( df_w_buckets )
Assign each row of `df` to a bucket by dividing the range of the
`bucket_var` column into `n_bins` number of equal width intervals.
Assign each row of ` df ` to a bucket by dividing the range of the ` bucket_var ` column into ` n_bins ` number of equal width intervals .
"""
    Assign each row of `df` to a bucket by dividing the range of the 
    `bucket_var` column into `n_bins` number of equal width intervals.
    
    df: DataFrame
    bucket_var: Name of the column of df to use for dividing.
    width: Positive width of the buckets
    boundary: Edge of one of the buckets, if the data extended that far
    first_break: All values below this (if any) are grouped into one bucket
    last_break: All values above this (if any) are grouped into one bucket
    
    Returns: df with the additional `bucket` column 
        The `bucket` column is Categorical data type consisting of Intervals
        that partition the interval from just below min(bucket_var) to 
        max(bucket_var).
    """ # Set bucket edges # Clip lower and upper buckets
df
bucket_var
width
boundary
first_break
last_break