text_plain_output_1.png
import datetime

import pandas as pd

import numpy as np
import pandas as pd
import re
import datetime
from sklearn.neighbors import NearestNeighbors
import matplotlib.pyplot as plt
input_dir = '/kaggle/input/tabular-playground-series-mar-2022/'

def handle_dates(df):
    df['datetime'] = pd.to_datetime(df['time'])
    df['time'] = [datetime.datetime.time(d) for d in df.loc[:, 'datetime']]
    time_mapping = {t: ii for ii, t in enumerate(train.time.unique())}
    df['time_number'] = [time_mapping[d] for d in df.loc[:, 'time']]
    df['date'] = [datetime.datetime.date(d) for d in df.loc[:, 'datetime']]
    df['weekday'] = [d.weekday() for d in df.datetime]
    return df

train = pd.read_csv(input_dir + 'train.csv')
test = pd.read_csv(input_dir + 'test.csv')
train = handle_dates(train)
test = handle_dates(test)
print('Train shape: ' + str(train.shape) + ', Test shape:' + str(test.shape))