image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

train_df = pd.read_csv('../input/catch-me-if-you-can/train_sessions.csv', index_col='session_id')
test_df = pd.read_csv('../input/catch-me-if-you-can/test_sessions.csv', index_col='session_id')

features = pd.DataFrame()
timepoints = train_df[['time%s' % i for i in range(1, 11)]]
sites = train_df[['site%s' % i for i in range(1, 11)]].fillna(0).astype(int).values
for td_index in range(1, 10):
    features['time_diff{}'.format(td_index)] = (pd.to_datetime(timepoints['time{}'.format(td_index + 1)]) - pd.to_datetime(timepoints['time{}'.format(td_index)])).dt.total_seconds().fillna(0)
features['time_of_session'] = np.sum(features, axis=1)
features['hour'] = pd.to_datetime(timepoints['time1']).dt.hour
features['day_of_week'] = pd.to_datetime(timepoints['time1']).dt.weekday
features['unique_sites'] = [len(np.unique(session[session != 0])) for session in sites]

plt.figure(figsize=(15, 10))
sns.distplot(features['time_of_session'], label='time')
plt.ylabel('Кол-во')
plt.xlabel('Продолжительность сессии')
plt.grid()