image_output_2.png image_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(counts.tail())
plt.figure(figsize=(14, 7))
sns.lineplot(data=counts, x='month', y='count', hue='year')
plt.show()