image_output_5.png image_output_7.png image_output_4.png image_output_6.png image_output_3.png image_output_2.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

train = pd.read_csv('../input/tabular-playground-series-mar-2022/train.csv')
test = pd.read_csv('../input/tabular-playground-series-mar-2022/test.csv', index_col='row_id')

train.time = pd.to_datetime(train.time)
train['daytime_id'] = ((train.time.dt.hour * 60 + train.time.dt.minute) / 20).astype(int)
train = train.set_index('row_id', drop=True)
train['roadway'] = train.x.astype('str') + '_' + train.y.astype('str') + '_' + train.direction.astype('str')
train['day_of_week'] = train.time.dt.dayofweek
test.time = pd.to_datetime(test.time)
test['roadway'] = test.x.astype('str') + '_' + test.y.astype('str') + '_' + test.direction.astype('str')
test['day_of_week'] = test.time.dt.dayofweek

# Histogram of all congestions
plot = sns.histplot(train['congestion'])
plot.set_title('Congestion Histogram')
plt.show()

rw = train.roadway.unique()
i = 0
while i < len(rw):
    fig, axs = plt.subplots(1, 5, figsize=(10, 3))
    sns.histplot(data=train, x=train.congestion[train.roadway == rw[i]], kde=True, color='skyblue', ax=axs[0])
    axs[0].set_title(f'{rw[i]}')
    sns.histplot(data=train, x=train.congestion[train.roadway == rw[i + 1]], kde=True, color='skyblue', ax=axs[1])
    axs[1].set_title(f'{rw[i + 1]}')
    sns.histplot(data=train, x=train.congestion[train.roadway == rw[i + 2]], kde=True, color='skyblue', ax=axs[2])
    axs[2].set_title(f'{rw[i + 2]}')
    sns.histplot(data=train, x=train.congestion[train.roadway == rw[i + 3]], kde=True, color='skyblue', ax=axs[3])
    axs[3].set_title(f'{rw[i + 3]}')
    sns.histplot(data=train, x=train.congestion[train.roadway == rw[i + 4]], kde=True, color='skyblue', ax=axs[4])
    axs[4].set_title(f'{rw[i + 4]}')
    i += 5
    plt.tight_layout()
    plt.show()