text_plain_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')

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('## Accident by year ##')
year_df = thai_accident_df['accident_date'].dt.year.value_counts().reset_index(name='c')
year_df.columns = ['year', 'count']
plt.title('All accident occur each year')
sns.barplot(data=year_df, x='year', y='count')
plt.ylabel('count')
plt.xlabel('Year')
plt.show()
plt.title('All appear accident_date')
sns.lineplot(data=year_df, x='year', y='count')
plt.ylabel('count')
plt.xlabel('Year')
plt.show()
plt.figure(figsize=(14, 7))
plt.title('Use Histogram')
sns.histplot(data=thai_accident_df['year'], discrete=True, element='step')
plt.show()
print('Describe accident by year')
print(thai_accident_df['year'].value_counts().describe())