I have a df like this:
data = {'ds': ['2024-02-01', '2024-01-01', '2023-12-01', '2024-02-01', '2023-12-01'],'y': [500, 600, 700, 800,500],'unique_id': [1, 1, 1, 2, 2]}input_df = pd.DataFrame(data)
I need a function to select the unique ids where the data is valid according to a minimum consecutive observations' parameter from last month backwards.
The expected output for a min_consecutive_observations == 2 is:
expected_output = {'ds': ['2024-02-01', '2024-01-01', '2023-12-01'],'y': [500, 600, 700],'unque_id': [1, 1, 1]}
I'm having trouble coding a function that achieves this.
I got last month like this:
last_month_input = datetime.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) - pd.DateOffset(months=1)
But can't wrap my ahead around on how to check for continuity from the last_month_input backwards.