Looping through combinations of subsets of data for processing
IIUC, you can use :
def crossubsets(df):
    labels = ["RA", "DS", "TP"]
    time_intervals = [7, 30, 60, 90, 120, None]
    group_dfs = df.loc[
        df["Association Label"].isin(labels)
    ].groupby("Association Label")

    data = []
    for l, g in group_dfs:
        for ti in time_intervals:
            s = (
                g[g["Status Date"] > (pd.Timestamp.now() - pd.Timedelta(ti, "d"))]
                if ti is not None else g
            )
            data.append(s["Status Labelled"].value_counts().rename(f"counts_{l}_{ti}"))

    return pd.concat(data, axis=1) #with optional .T to have 18 rows instead of cols


I am processing sales data, sub-setting across a combination of two distinct dimensions.
The first is a category as indicated by each of these three indicators ['RA','DS','TP']. There are more indicators in the data; however, those are the only ones of interest, and the others not mentioned but in the data can be ignored.
In combination with those indicators, I want to subset across varying time intervals 7 days back, 30 days back, 60 days back, 90 days back, 120 days back, and no time constraint
Without looping through this would create 18 distinct functions for those combinations of dimensions 3 categories x 6 time which was what I first started to do
for example a function that subsets on DS and 7 days back:
def seven_days_ds(df):

    subset = df[df['Status Date'] > (datetime.now() - pd.to_timedelta("7day"))]
    subset = subset[subset['Association Label']=="DS"]
    
    grouped_subset = subset.groupby(['Status Labelled'])
    status_counts_seven_ds = (pd.DataFrame(grouped_subset['Status Labelled'].count()))
    status_counts_seven_ds.columns = ['Counts']
    status_counts_seven_ds = status_counts_seven_ds.reset_index()
    
    return status_counts_seven_ds #(the actual function is more complicated than this).

And then repeat this, but changing the subset criteria for each combination of category and time-delta for 18 combinations of the variables of interest. Obviously, this is not ideal.
Is there a way to have a single function that creates those 18 objects, or (ideally), a single object whose columns indicate the dimensions being subset on? ie counts_ds_7 etc.
Or is this not possible, and I'm stuck doing it the long way doing them all separately?
