text_html_output_1.png application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import seaborn as sns

df = pd.read_csv('/kaggle/input/thailand-fatal-road-accident/thailand_fatal_raod_accident_2011_2022.csv')

df['official_death_date'] = pd.to_datetime(df['official_death_date'])

thai_accident_df = df.dropna(subset='accident_date').copy()

thai_accident_df['accident_date'] = pd.to_datetime(thai_accident_df['accident_date'])
thai_accident_df.dtypes

thai_accident_df.describe().T

import matplotlib.pyplot as plt
import seaborn as sns
thai_accident_df = df.dropna(subset='accident_date').copy()
thai_accident_df['accident_date'] = pd.to_datetime(thai_accident_df['accident_date'])
thai_accident_df['year'], thai_accident_df['month'], thai_accident_df['day'] = (thai_accident_df['accident_date'].dt.year, thai_accident_df['accident_date'].dt.month, thai_accident_df['accident_date'].dt.day)
def thai_accident_from_to(from_date=thai_accident_df['accident_date'].min(), to_date=thai_accident_df['accident_date'].max()):
    df = thai_accident_df[(thai_accident_df['accident_date'] >= from_date) & (thai_accident_df['accident_date'] < to_date)]
    return df

counts = thai_accident_df.groupby(['year', 'month']).size().reset_index(name='count')

print('Simple data below\n')
print(f"All accident data from {thai_accident_df['accident_date'].min().date()} to {thai_accident_df['accident_date'].max().date()} \n{thai_accident_df.shape[0]} cases\n")
print('# By Gender')
gender_count = thai_accident_df['gender'].value_counts().reset_index()
gender_count.columns = ['gender', 'g_count']
gender_count['%'] = gender_count['g_count'] / gender_count['g_count'].sum() * 100
print(gender_count)
print('\n# By Vehicle type')
print(thai_accident_df['vehicle_type'].value_counts())
print('\n# By province')
print(thai_accident_df['province_en'].value_counts())
print(thai_accident_df['province_en'].value_counts().describe())