Skip to content

Instantly share code, notes, and snippets.

@AVJdataminer
Created April 29, 2020 19:37
Show Gist options
  • Save AVJdataminer/83a203d079ca8349881d859bb760d7d7 to your computer and use it in GitHub Desktop.
Save AVJdataminer/83a203d079ca8349881d859bb760d7d7 to your computer and use it in GitHub Desktop.
def new_dt_split(date_col, X, y, input_date):
date_col = pd.to_datetime(date_col)
xw_date=pd.DataFrame(X).merge(date_col, left_index=True, right_index=True)
X_train = xw_date.loc[xw_date['date'] <= input_date].drop(['date'], axis=1).values
X_test = xw_date.loc[xw_date['date'] >= input_date].drop(['date'], axis=1).values
yw_date=pd.DataFrame(y).merge(date_col, left_index=True, right_index=True)
y_train = yw_date.loc[yw_date['date'] <= input_date].drop(['date'], axis=1).values
y_test = yw_date.loc[yw_date['date'] >= input_date].drop(['date'], axis=1).values
return X_train, X_test, y_train, y_test
X_train, X_test, y_train, y_test=new_dt_split(df['date'], X_scaled, y, "2020-04-12")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment