pat2vec.pat2vec_search.nearest
Functions
|
Finds the nearest date and its corresponding value within a time range. |
- pat2vec.pat2vec_search.nearest.nearest(date, lookup_dates_and_values, date_col, value_col, max_time_before=datetime.timedelta(days=42), max_time_after=datetime.timedelta(days=350))[source]
Finds the nearest date and its corresponding value within a time range.
This function searches a DataFrame for the row with a date closest to a given reference date, within a specified time window.
- Parameters:
date (
datetime
) – The reference date to find the nearest date around.lookup_dates_and_values (
DataFrame
) – DataFrame containing dates and values.date_col (
str
) – The name of the column containing dates in the DataFrame.value_col (
str
) – The name of the column containing values to be returned.max_time_before (
timedelta
) – Maximum time before the reference date to consider. Defaults to 6 weeks.max_time_after (
timedelta
) – Maximum time after the reference date to consider. Defaults to 50 weeks.
- Return type:
Optional
[Any
]- Returns:
The value from value_col corresponding to the nearest date, or None if no date is found within the specified range.