def select_date_range(df, start_date, end_date, drop_zero_cols=True):
    """Extract a range of dates from a dataframe with a datetime index,
    then remove any columns which are left empty (full of zeros)."""

    df_slice = df.copy()

    if start_date is not None:
        df_slice = df_slice[df_slice.index >= start_date]
    if end_date is not None:
        df_slice = df_slice[df_slice.index <= end_date]

    if drop_zero_cols:
        nonzero_cols = df_slice.columns[~(df_slice == 0).all()]
        df_slice = df_slice[nonzero_cols]

    return df_slice