I have the following python function: def removeoldhistory(calendar : pd.DataFrame,…
- User
I have the following python function:
def remove_old_history(calendar : pd.DataFrame, timeperiod : int, full_days : int, day_to_keep :int) -> pd.DataFrame: ''' Removes all rows from calendar, where the date is older than (today - timeperiod) and all non-monday values that are older than (today - full_days) days
Args: calendar (pd.DataFrame): The calendar that contains the history data. It has to contain a column named Date. timeperiod (int): Number of days that will be kept in the history from today. full_days (int): Number of days that will be kept fully from today. Every day that is after full_days days are deleted if they are not the day that is defined in day_to_keep. day_to_keep (int): The numer representant of the day that should always be kept int the timeriod. 0 is Monday. Returns: The new DataFrame with the trimmed history. ''' today = pd.to_datetime(date.today()) last_date_to_keep = today - timedelta(days=timeperiod) last_full_day = today - timedelta(days=full_days) calendar["Date"] = pd.to_datetime(calendar["Date"]) calendar = calendar[calendar["Date"] > last_date_to_keep] calendar = calendar[(calendar["Date"] > last_full_day) | (calendar["Date"].dt.dayofweek == day_to_keep)] return calendar
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.