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

year_df = thai_accident_df['accident_date'].dt.year.value_counts().reset_index(name='c')
year_df.columns = ['year', 'count']

print('Try......')
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
fig.suptitle('1st try subplots', y=1.05)
sns.histplot(ax=ax[0], x=thai_accident_df['year'], discrete=True)
ax[0].set_title('Plot using histogram', y=1.05)
ax[0].bar_label(ax[0].containers[1], rotation=45)
sns.barplot(ax=ax[1], data=year_df, x='year', y='count')
ax[1].set_title('Plot using barplot', y=1.05)
ax[1].bar_label(ax[1].containers[0], rotation=35)
ax[1].set_xticklabels(ax[1].get_xticklabels(), rotation=45)
plt.show()