{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### CREDITS\n* [baseline average 1.47](https://www.kaggle.com/mlconsult/baseline-average-1-47)\n* [BaseLine Model: Player Mean or Median ?](https://www.kaggle.com/ulrich07/baseline-model-player-mean-or-median)\n* [Fork - MLB baseline avergage 1.47](https://www.kaggle.com/junichih/mlb-baseline-median-1-45) \n\n### UPDATES\n* **V1**: Lags up to 3, 10 Epochs \n* **V2**: Lags up to 3, 20 Epochs\n* **V5**: Lags up to 20, 10 Epochs\n* **V6**: Lags up to 20, 10 Epochs with Stratified KFold (5 Folds)\n* **V7**: Lags up to 20, 50 Epochs with Stratified KFold (5 Folds)\n* **V8**: Lags up to 30, 10 Epochs with Stratified KFold (5 Folds)\n* **V9**: Lags up to 20, 10 Epochs with Stratified KFold (5 Folds) & Bigger Network\n* **V10**: Lags up to 15, 10 Epochs with Stratified KFold (5 Folds)\n* **V11**: Lags up to 17, 10 Epochs with Stratified KFold (5 Folds)\n* **V12**: Lags up to 20, 10 Epochs with Stratified KFold (10 Folds)\n* **V14**: Lags up to 20, 10 Epochs with Stratified KFold (10 Folds) & OFFSETof 45 days\n\n### Please **Upvote** if you find this helpful 👽","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-16T15:46:24.94492Z","iopub.execute_input":"2021-06-16T15:46:24.945502Z","iopub.status.idle":"2021-06-16T15:46:25.761799Z","shell.execute_reply.started":"2021-06-16T15:46:24.945463Z","shell.execute_reply":"2021-06-16T15:46:25.760806Z"}}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom datetime import timedelta\nfrom tqdm import tqdm\nimport gc\nfrom functools import reduce\nfrom sklearn.model_selection import StratifiedKFold","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_df(df, col, bool_in=False):\n    tp = df.loc[ ~df[col].isnull() ,[col]].copy()\n    df.drop(col, axis=1, inplace=True)\n    \n    tp[col] = tp[col].str.replace(\"null\",'\"\"')\n    if bool_in:\n        tp[col] = tp[col].str.replace(\"false\",'\"False\"')\n        tp[col] = tp[col].str.replace(\"true\",'\"True\"')\n    tp[col] = tp[col].apply(lambda x: eval(x) )\n    a = tp[col].sum()\n    gc.collect()\n    return pd.DataFrame(a)\n#===============","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:44:56.96137Z","iopub.execute_input":"2021-06-16T15:44:56.961802Z","iopub.status.idle":"2021-06-16T15:44:56.969075Z","shell.execute_reply.started":"2021-06-16T15:44:56.961753Z","shell.execute_reply":"2021-06-16T15:44:56.968316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT_DIR = \"../input/mlb-player-digital-engagement-forecasting\"","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:44:57.198922Z","iopub.execute_input":"2021-06-16T15:44:57.199416Z","iopub.status.idle":"2021-06-16T15:44:57.2035Z","shell.execute_reply.started":"2021-06-16T15:44:57.199387Z","shell.execute_reply":"2021-06-16T15:44:57.202751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## UTILITY FUNCTIONS","metadata":{}},{"cell_type":"code","source":"#=======================#\ndef flatten(df, col):\n    du = (df.pivot(index=\"playerId\", columns=\"EvalDate\", \n               values=col).add_prefix(f\"{col}_\").\n      rename_axis(None, axis=1).reset_index())\n    return du\n#============================#\ndef reducer(left, right):\n    return left.merge(right, on=\"playerId\")\n#========================","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:44:57.778523Z","iopub.execute_input":"2021-06-16T15:44:57.778838Z","iopub.status.idle":"2021-06-16T15:44:57.783432Z","shell.execute_reply.started":"2021-06-16T15:44:57.778811Z","shell.execute_reply":"2021-06-16T15:44:57.782834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TGTCOLS = [\"target1\",\"target2\",\"target3\",\"target4\"]\ndef train_lag(df, lag=1):\n    dp = df[[\"playerId\",\"EvalDate\"]+TGTCOLS].copy()\n    dp[\"EvalDate\"]  =dp[\"EvalDate\"] + timedelta(days=lag) \n    df = df.merge(dp, on=[\"playerId\", \"EvalDate\"], suffixes=[\"\",f\"_{lag}\"], how=\"left\")\n    return df\n#=================================\ndef test_lag(sub):\n    sub[\"playerId\"] = sub[\"date_playerId\"].apply(lambda s: int(  s.split(\"_\")[1]  ) )\n    assert sub.date.nunique() == 1\n    dte = sub[\"date\"].unique()[0]\n    \n    eval_dt = pd.to_datetime(dte, format=\"%Y%m%d\")\n    dtes = [eval_dt + timedelta(days=-k) for k in LAGS]\n    mp_dtes = {eval_dt + timedelta(days=-k):k for k in LAGS}\n    \n    sl = LAST.loc[LAST.EvalDate.between(dtes[-1], dtes[0]), [\"EvalDate\",\"playerId\"]+TGTCOLS].copy()\n    sl[\"EvalDate\"] = sl[\"EvalDate\"].map(mp_dtes)\n    du = [flatten(sl, col) for col in TGTCOLS]\n    du = reduce(reducer, du)\n    return du, eval_dt\n    #\n#===============","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:44:58.119337Z","iopub.execute_input":"2021-06-16T15:44:58.119837Z","iopub.status.idle":"2021-06-16T15:44:58.128205Z","shell.execute_reply.started":"2021-06-16T15:44:58.119793Z","shell.execute_reply":"2021-06-16T15:44:58.127687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#tr = pd.read_csv(f\"{ROOT_DIR}/train.csv\")\ntr = pd.read_csv(\"../input/mlb-data/target.csv\")\nprint(tr.shape)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:44:58.91637Z","iopub.execute_input":"2021-06-16T15:44:58.916883Z","iopub.status.idle":"2021-06-16T15:45:03.105687Z","shell.execute_reply.started":"2021-06-16T15:44:58.916836Z","shell.execute_reply":"2021-06-16T15:45:03.104667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tr[\"EvalDate\"] = pd.to_datetime(tr[\"EvalDate\"])\ntr[\"EvalDate\"] = tr[\"EvalDate\"] + timedelta(days=-1)\ntr[\"EvalYear\"] = tr[\"EvalDate\"].dt.year","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:03.107348Z","iopub.execute_input":"2021-06-16T15:45:03.107706Z","iopub.status.idle":"2021-06-16T15:45:03.779939Z","shell.execute_reply.started":"2021-06-16T15:45:03.107669Z","shell.execute_reply":"2021-06-16T15:45:03.779278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MED_DF = tr.groupby([\"playerId\",\"EvalYear\"])[TGTCOLS].median().reset_index()\nMEDCOLS = [\"tgt1_med\",\"tgt2_med\", \"tgt3_med\", \"tgt4_med\"]\nMED_DF.columns = [\"playerId\",\"EvalYear\"] + MEDCOLS","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:03.781557Z","iopub.execute_input":"2021-06-16T15:45:03.782074Z","iopub.status.idle":"2021-06-16T15:45:04.234107Z","shell.execute_reply.started":"2021-06-16T15:45:03.782037Z","shell.execute_reply":"2021-06-16T15:45:04.233461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MED_DF.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:04.235419Z","iopub.execute_input":"2021-06-16T15:45:04.235982Z","iopub.status.idle":"2021-06-16T15:45:04.252126Z","shell.execute_reply.started":"2021-06-16T15:45:04.235933Z","shell.execute_reply":"2021-06-16T15:45:04.251357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MAX_LAG = 20\nOFFSET = 45\nLAGS = list(range(OFFSET, MAX_LAG + OFFSET))\nFECOLS = [f\"{col}_{lag}\" for lag in reversed(LAGS) for col in TGTCOLS]","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:04.253071Z","iopub.execute_input":"2021-06-16T15:45:04.253291Z","iopub.status.idle":"2021-06-16T15:45:04.256519Z","shell.execute_reply.started":"2021-06-16T15:45:04.253271Z","shell.execute_reply":"2021-06-16T15:45:04.255927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LAGS","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:04.25735Z","iopub.execute_input":"2021-06-16T15:45:04.257785Z","iopub.status.idle":"2021-06-16T15:45:04.26911Z","shell.execute_reply.started":"2021-06-16T15:45:04.25773Z","shell.execute_reply":"2021-06-16T15:45:04.268329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nfor lag in tqdm(LAGS):\n    tr = train_lag(tr, lag=lag)\n    gc.collect()\n#===========\ntr = tr.sort_values(by=[\"playerId\", \"EvalDate\"])\nprint(tr.shape)\ntr = tr.dropna()\nprint(tr.shape)\ntr = tr.merge(MED_DF, on=[\"playerId\",\"EvalYear\"])\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:45:04.270025Z","iopub.execute_input":"2021-06-16T15:45:04.270392Z","iopub.status.idle":"2021-06-16T15:46:01.516455Z","shell.execute_reply.started":"2021-06-16T15:45:04.270356Z","shell.execute_reply":"2021-06-16T15:46:01.51562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tr.head(1)","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:01.518226Z","iopub.execute_input":"2021-06-16T15:46:01.518488Z","iopub.status.idle":"2021-06-16T15:46:01.545586Z","shell.execute_reply.started":"2021-06-16T15:46:01.518461Z","shell.execute_reply":"2021-06-16T15:46:01.544822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = tr[FECOLS+MEDCOLS].values\ny = tr[TGTCOLS].values\ncl = tr[\"playerId\"].values","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:01.547719Z","iopub.execute_input":"2021-06-16T15:46:01.548239Z","iopub.status.idle":"2021-06-16T15:46:03.673129Z","shell.execute_reply.started":"2021-06-16T15:46:01.548207Z","shell.execute_reply":"2021-06-16T15:46:03.672504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NFOLDS = 10\nskf = StratifiedKFold(n_splits=NFOLDS)\nfolds = skf.split(X, cl)\nfolds = list(folds)","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:31.916136Z","iopub.execute_input":"2021-06-16T15:46:31.91646Z","iopub.status.idle":"2021-06-16T15:46:35.025512Z","shell.execute_reply.started":"2021-06-16T15:46:31.916431Z","shell.execute_reply":"2021-06-16T15:46:35.024529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:39.013585Z","iopub.execute_input":"2021-06-16T15:46:39.013956Z","iopub.status.idle":"2021-06-16T15:46:39.018904Z","shell.execute_reply.started":"2021-06-16T15:46:39.013923Z","shell.execute_reply":"2021-06-16T15:46:39.018256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Neural Net Training","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow.keras.layers as L\nimport tensorflow.keras.models as M\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error\nfrom tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:45.876607Z","iopub.execute_input":"2021-06-16T15:46:45.87695Z","iopub.status.idle":"2021-06-16T15:46:51.06606Z","shell.execute_reply.started":"2021-06-16T15:46:45.876923Z","shell.execute_reply":"2021-06-16T15:46:51.065313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_model(n_in):\n    inp = L.Input(name=\"inputs\", shape=(n_in,))\n    nh = 50\n    x = L.Dense(nh, activation=\"relu\", name=\"d1\")(inp)\n    x = L.Dense(nh, activation=\"relu\", name=\"d2\")(x)\n    #x = L.Dense(nh, activation=\"relu\", name=\"d3\")(x)\n    preds = L.Dense(4, activation=\"linear\", name=\"preds\")(x)\n    \n    model = M.Model(inp, preds, name=\"ANN\")\n    model.compile(loss=\"mean_absolute_error\", optimizer=\"adam\")\n    return model","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:51.067267Z","iopub.execute_input":"2021-06-16T15:46:51.06775Z","iopub.status.idle":"2021-06-16T15:46:51.074331Z","shell.execute_reply.started":"2021-06-16T15:46:51.067714Z","shell.execute_reply":"2021-06-16T15:46:51.073816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"net = make_model(X.shape[1])\nprint(net.summary())","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:46:51.075591Z","iopub.execute_input":"2021-06-16T15:46:51.076019Z","iopub.status.idle":"2021-06-16T15:46:51.188727Z","shell.execute_reply.started":"2021-06-16T15:46:51.075992Z","shell.execute_reply":"2021-06-16T15:46:51.187881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oof = np.zeros(y.shape)\nnets = []\nEPOCHS  = 10\nfor idx in range(NFOLDS):\n    print(\"FOLD:\", idx)\n    tr_idx, val_idx = folds[idx]\n    ckpt = ModelCheckpoint(f\"w{idx}.h5\", monitor='val_loss', verbose=1, save_best_only=True,mode='min')\n    reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.2,patience=3, min_lr=0.0005)\n    es = EarlyStopping(monitor='val_loss', patience=6)\n    reg = make_model(X.shape[1])\n    reg.fit(X[tr_idx], y[tr_idx], epochs=EPOCHS, batch_size=30_000, \n            validation_data=(X[val_idx], y[val_idx]),\n            verbose=1, callbacks=[ckpt, reduce_lr, es])\n    reg.load_weights(f\"w{idx}.h5\")\n    oof[val_idx] = reg.predict(X[val_idx], batch_size=50_000, verbose=1)\n    nets.append(reg)\n    gc.collect()\n    #\n#","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:50:18.267289Z","iopub.execute_input":"2021-06-16T15:50:18.267634Z","iopub.status.idle":"2021-06-16T15:52:13.175151Z","shell.execute_reply.started":"2021-06-16T15:50:18.267606Z","shell.execute_reply":"2021-06-16T15:52:13.17437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#reg.fit(X, y, epochs=10, batch_size=30_000, validation_split=0.3)","metadata":{"execution":{"iopub.status.busy":"2021-06-15T20:11:26.331341Z","iopub.execute_input":"2021-06-15T20:11:26.331626Z","iopub.status.idle":"2021-06-15T20:11:26.335327Z","shell.execute_reply.started":"2021-06-15T20:11:26.331597Z","shell.execute_reply":"2021-06-15T20:11:26.33433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mae = mean_absolute_error(y, oof)\nmse = mean_squared_error(y, oof, squared=False)\nprint(\"mae:\", mae)\nprint(\"mse:\", mse)","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:52:42.495973Z","iopub.execute_input":"2021-06-16T15:52:42.496272Z","iopub.status.idle":"2021-06-16T15:52:42.717532Z","shell.execute_reply.started":"2021-06-16T15:52:42.496247Z","shell.execute_reply":"2021-06-16T15:52:42.716587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Historical information to use in prediction time\nbound_dt = pd.to_datetime(\"2021-01-01\")\nLAST = tr.loc[tr.EvalDate>bound_dt].copy()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:52:54.512119Z","iopub.execute_input":"2021-06-16T15:52:54.512424Z","iopub.status.idle":"2021-06-16T15:52:54.684233Z","shell.execute_reply.started":"2021-06-16T15:52:54.512397Z","shell.execute_reply":"2021-06-16T15:52:54.683327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LAST_MED_DF = MED_DF.loc[MED_DF.EvalYear==2021].copy()\nLAST_MED_DF.drop(\"EvalYear\", axis=1, inplace=True)\ndel tr","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:52:55.651265Z","iopub.execute_input":"2021-06-16T15:52:55.651588Z","iopub.status.idle":"2021-06-16T15:52:55.664984Z","shell.execute_reply.started":"2021-06-16T15:52:55.65156Z","shell.execute_reply":"2021-06-16T15:52:55.663983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LAST.shape, LAST_MED_DF.shape, MED_DF.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:53:01.486014Z","iopub.execute_input":"2021-06-16T15:53:01.486376Z","iopub.status.idle":"2021-06-16T15:53:01.49157Z","shell.execute_reply.started":"2021-06-16T15:53:01.486326Z","shell.execute_reply":"2021-06-16T15:53:01.490843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#nets[0].summary()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:53:33.146384Z","iopub.execute_input":"2021-06-16T15:53:33.146676Z","iopub.status.idle":"2021-06-16T15:53:33.14976Z","shell.execute_reply.started":"2021-06-16T15:53:33.146652Z","shell.execute_reply":"2021-06-16T15:53:33.14916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\"\"\"\nimport mlb\nFE = []; SUB = [];\nenv = mlb.make_env() # initialize the environment\niter_test = env.iter_test() # iterator which loops over each date in test set\n\nfor (test_df, sub) in iter_test:\n    # Features computation at Evaluation Date\n    sub = sub.reset_index()\n    sub_fe, eval_dt = test_lag(sub)\n    sub_fe = sub_fe.merge(LAST_MED_DF, on=\"playerId\", how=\"left\")\n    sub_fe = sub_fe.fillna(0.)\n    \n    _preds = 0.\n    for reg in nets:\n        _preds += reg.predict(sub_fe[FECOLS + MEDCOLS]) / NFOLDS\n    sub_fe[TGTCOLS] = np.clip(_preds, 0, 100)\n    sub.drop([\"date\"]+TGTCOLS, axis=1, inplace=True)\n    sub = sub.merge(sub_fe[[\"playerId\"]+TGTCOLS], on=\"playerId\", how=\"left\")\n    sub.drop(\"playerId\", axis=1, inplace=True)\n    sub = sub.fillna(0.)\n    # Submit\n    env.predict(sub)\n    # Update Available information\n    sub_fe[\"EvalDate\"] = eval_dt\n    #sub_fe.drop(MEDCOLS, axis=1, inplace=True)\n    LAST = LAST.append(sub_fe)\n    LAST = LAST.drop_duplicates(subset=[\"EvalDate\",\"playerId\"], keep=\"last\")\n#\"\"\"","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:53:35.172134Z","iopub.execute_input":"2021-06-16T15:53:35.17245Z","iopub.status.idle":"2021-06-16T15:53:41.129416Z","shell.execute_reply.started":"2021-06-16T15:53:35.172425Z","shell.execute_reply":"2021-06-16T15:53:41.128573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:53:45.320276Z","iopub.execute_input":"2021-06-16T15:53:45.320604Z","iopub.status.idle":"2021-06-16T15:53:45.331665Z","shell.execute_reply.started":"2021-06-16T15:53:45.320574Z","shell.execute_reply":"2021-06-16T15:53:45.3309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LAST.shape, sub_fe.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-16T15:54:56.416218Z","iopub.execute_input":"2021-06-16T15:54:56.416563Z","iopub.status.idle":"2021-06-16T15:54:56.421909Z","shell.execute_reply.started":"2021-06-16T15:54:56.41653Z","shell.execute_reply":"2021-06-16T15:54:56.420783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-06-14T11:54:08.185136Z","iopub.execute_input":"2021-06-14T11:54:08.185518Z","iopub.status.idle":"2021-06-14T11:54:08.191895Z","shell.execute_reply.started":"2021-06-14T11:54:08.185486Z","shell.execute_reply":"2021-06-14T11:54:08.190784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"execution":{"iopub.status.busy":"2021-06-14T11:54:09.094613Z","iopub.execute_input":"2021-06-14T11:54:09.094993Z","iopub.status.idle":"2021-06-14T11:54:09.131741Z","shell.execute_reply.started":"2021-06-14T11:54:09.094961Z","shell.execute_reply":"2021-06-14T11:54:09.130631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_tr[\"dte\"] = pd.to_datetime(df_tr[\"date\"], format='%Y%m%d')","metadata":{"execution":{"iopub.status.busy":"2021-06-14T09:50:49.268983Z","iopub.execute_input":"2021-06-14T09:50:49.269332Z","iopub.status.idle":"2021-06-14T09:50:49.279831Z","shell.execute_reply.started":"2021-06-14T09:50:49.269304Z","shell.execute_reply":"2021-06-14T09:50:49.278753Z"},"trusted":true},"execution_count":null,"outputs":[]}]}