def week_of_month()

in fclib/fclib/feature_engineering/feature_utils.py [0:0]


def week_of_month(date_time):
    """Returns the week of the month for a specified date.

    Args:
        dt (Datetime): Input date

    Returns:
        wom (Integer): Week of the month of the input date
    """

    def _week_of_month(date_time):
        from math import ceil

        first_day = date_time.replace(day=1)
        dom = date_time.day
        adjusted_dom = dom + first_day.weekday()
        wom = int(ceil(adjusted_dom / 7.0))
        return wom

    if isinstance(date_time, pd.Series):
        return date_time.apply(lambda x: _week_of_month(x))
    else:
        return _week_of_month(date_time)