def year_week(y, w): try: if w not in ['', np.nan, None] and y not in ['', np.nan, None]: week = Week(int(y), int(w)) date = week.startdate() + timedelta(3) return date else: return '' except: return ''
def _parse_datetimes(date_int: int, time_type: str, date_format: str = "%Y%m%d") -> Union[pd.Timestamp]: # annotating nan errors """Convert a date or epiweeks string into timestamp objects. Datetimes (length 8) are converted to their corresponding date, while epiweeks (length 6) are converted to the date of the start of the week. Returns nan otherwise Epiweeks use the CDC format. :param date_int: Int representation of date. :param date_format: String of the date format to parse. :returns: Timestamp. """ date_str = str(date_int) if time_type == "day": return pd.to_datetime(date_str, format=date_format) if time_type == "week": epiwk = Week(int(date_str[:4]), int(date_str[-2:])) return pd.to_datetime(epiwk.startdate()) return np.nan
n_neurons = n_neurons data_path = data_path ind_og = pd.read_csv(data_path) # ind = data.set_index(["WEEK"]) region = "Region" ind = ind_og.loc[ind_og["REGION"] == "Region " + str(r)] ind_next = ind_og[0:300] from epiweeks import Week, Year date = [] for item, row in ind.iterrows(): week = Week(row["YEAR"], row["WEEK"]) # print(row["YEAR"], row["WEEK"], week.startdate()) date.append(week.startdate()) ind["DATE"] = date new_ind = ind[['DATE', '% WEIGHTED ILI']] # ,'WEEK']] new_ind.index = new_ind['DATE'] series = new_ind.drop(['DATE'], axis=1) all_32_forecasts = [] for r in range(1, 11): # date-time parsing function for loading the dataset def parser(x): return datetime.strptime('190' + x, '%Y-%m') # convert time series into supervised learning problem