Lessons from airplane crashes: A Python look back at the Jeju Air disaster

On December 29, 2024, we were shocked by the tragic news of the Jeju Air crash. Our deepest condolences go out to the victims and their families at this difficult time.

In honor of those who have lost their lives, this post is dedicated to analyzing and learning from aircraft accidents with data-driven insights. It is my hope that together we can reflect, learn, and build a safer future.

Aircraft accident data overview

The Kaggle Aircraft Accident Datasetcontains a wealth of information related to aviation accidents and is an important resource for data analysis and safety improvement research. Key features of the dataset include

The dataset name is Aviation Accident Database Synopses To, U.S. National Transportation Safety Board (NTSB)'s aviation accident database. For reference, the detailed dataset can be found in the Aviation Accident Database Synopses on Kaggle for more information.

Kaggle Dataset Overview Summary

ItemDescription.
Dataset nameAviation Accident Database Synopses
SourceU.S. National Transportation Safety Board (NTSB)
LicensesCC0 1.0 Universal
Key columns– Event_Date: Incident date
– Location, Country: Incident Location
– Broad.phase.of.flight: Flight Phase
– Weather.Condition: Weather conditions
– Total.Fatal.Injuries: Number of deaths
– Probable_Cause: Incident Cause
Purpose of use- Analyze incident trends, improve technology, and develop policies

Dataset features

  • When and where incidents occurVisualize data by incident year and location to analyze patterns.
  • Incidents by flight phase: Identify trends in incidents during specific phases (e.g., landing, takeoff).
  • Scale of damage: Assess the severity of the incident through the number of fatalities, injuries, and survivors.

This dataset analyzes aircraft accidents and provides practical insights to prevent catastrophic events like airliner crashes.

Analyzing Aircraft Accident Data with Python Visualizations

Pythonis a versatile programming language that helps researchers and analysts discover insights within complex data sets. Analyzing aircraft accidents with Python visualizations can identify patterns and outliers for policy decisions and technical improvements.

Below is a code snippet for visualizing aircraft accident data in Python. This analysis can help you gain a deeper understanding of trends that may have contributed to tragedies like the recent Jeju Air crash. The code is long, but we've broken it down to make it easier to understand in the code walkthrough in the concluding section.

Setting up the # Kaggle API and downloading data
!pip install kaggle -q # Install the Kaggle library
import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px

Set up the # Kaggle API key
os.environ['KAGGLE_CONFIG_DIR'] = '/content' # Set to current directory
!chmod 600 /content/kaggle.json # Set permissions

# Download the Kaggle dataset
!kaggle datasets download -d khsamaha/aviation-accident-database-synopses -p /content/aviation_data --unzip

Load # data
file_path = "/content/aviation_data/AviationData.csv"
df = pd.read_csv(file_path, encoding='ISO-8859-1', low_memory=False)

Verify and correct the # column names
df.rename(columns={"Event Date": "Event_Date", "Broad.phase.of.flight": "Phase_of_Flight"}, inplace=True)

# Convert dates and create years
df.rename(columns={'Event.Date': 'Event_Date'}, inplace=True)
df['Event_Date'] = pd.to_datetime(df['Event_Date'], errors='coerce')
df['Year'] = df['Event_Date'].dt.year

Remove rows with # missing values
df = df.dropna(subset=['Phase_of_Flight'])

Count the number of incidents per # phase of flight
phase_counts = (
    df.groupby(['Phase_of_Flight', 'Year'])
    .size()
    .reset_index(name='count')
)

# matplotlib default font setting (to avoid warnings)
plt.rcParams['font.family'] = 'DejaVu Sans' # Fonts supported by default in Colab

# 1. Total accidents by phase of flight (Bar Chart)
plt.figure(figsize=(12, 6))
total_by_phase = phase_counts.groupby('Phase_of_Flight')['count'].sum().sort_values()
sns.barplot(x=total_by_phase.values, y=total_by_phase.index, palette='viridis')
plt.title('Total Accidents by Phase of Flight')
plt.xlabel('Number of Accidents')
plt.ylabel('Phase of Flight')
plt.tight_layout()
plt.show()

# 2. Annual accident trends by phase of flight (Line Chart)
plt.figure(figsize=(15, 8))
for phase in phase_counts['Phase_of_Flight'].unique():
    phase_data = phase_counts[phase_counts['Phase_of_Flight'] == phase]
    plt.plot(phase_data['Year'], phase_data['count'], marker='o', label=phase)

plt.title('Annual Accident Trends by Phase of Flight')
plt.xlabel('Year')
plt.ylabel('Number of Accidents')
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

# 3. Heatmap of accidents by year and phase of flight
pivot_data = phase_counts.pivot(index='Phase_of_Flight', columns='Year', values='count')
plt.figure(figsize=(15, 8))
sns.heatmap(pivot_data, cmap='viridis', cbar_kws={'label': 'Number of Accidents'})
plt.title('Accidents by Year and Phase of Flight (Heatmap)')
plt.xlabel('Year')
plt.ylabel('Phase of Flight')
plt.tight_layout()
plt.show()

# 4. Accident proportion by phase of flight (Last 10 years - Interactive Pie Chart)
max_year = df['Year'].max()
recent_data = df[df['Year'] >= max_year - 10]
recent_counts = (
    recent_data.groupby('Phase_of_Flight')
    .size()
    .reset_index(name='count')
)
recent_counts['percentage'] = recent_counts['count'] / recent_counts['count'].sum() * 100

fig = px.pie(
    recent_counts,
    values='percentage',
    names='Phase_of_Flight',
    title='Proportion of Accidents by Phase of Flight (Last 10 Years)',
    color_discrete_sequence=px.colors.sequential.Viridis
)
fig.show()

# 5. Monthly accident patterns (Line Chart)
df['Month'] = df['Event_Date'].dt.month
monthly_accidents = (
    df.groupby(['Phase_of_Flight', 'Month'])
    .size()
    .reset_index(name='count')
)

plt.figure(figsize=(15, 8))
sns.lineplot(data=monthly_accidents, x='Month', y='count',
             hue='Phase_of_Flight', marker='o')
plt.title('Monthly Accident Patterns by Phase of Flight')
plt.xlabel('Month')
plt.ylabel('Number of Accidents')
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

# basic statistics output
summary_stats = (
    phase_counts.groupby('Phase_of_Flight')
    .agg({'count': ['mean', 'std', 'min', 'max']})
    .round(2)
)
print("\n=== Summary Statistics for Accidents by Phase of Flight ===")
print(summary_stats)

Analyze and derive insights

1. Total Accidents by Phase of Flight (Bar Chart)

항공기 사고 막대그래프 이미지
  • Interpretation: Most incidents are caused by Landing(landing) and Takeoff(takeoff) phase, indicating that this is the most critical phase in airline operations. Relatively speaking Other, Unknown, and Standing The frequency of incidents is very low in the phase.
  • Insights:
    • The landing and takeoff phases rely heavily on collaboration between pilots and air traffic controllers, the performance of the aircraft, weather conditions, and more, so safety measures are critical.
    • Cruise Although the stage is altitude maintained and stable, it has the third highest accident rate and needs improvement here as well.

2. Annual Accident Trends by Phase of Flight (Line Chart)

항공기 사고 라인그래프 이미지
  • Interpretation: Overall incidents are trending downward over time, particularly for the Cruiseand Landingthe reduction in incidents is significant.
  • Insights:
    • Advances in aircraft technology, stricter regulations, and improved training programs are likely the main culprits.
    • A spike in incidents in a given year may be related to events in that year or to specific technical/environmental factors.

3. Heatmap of Accidents by Year and Phase of Flight

항공기 사고 히트맵 이미지
  • Interpretation: Landing (Landing) and takeoff (Takeoff) stage, a high frequency of incidents is observed across all years. For a given year's Approachand Cruise Thinking in steps is also noticeable.
  • Insights:
    • The landing and takeoff phases are consistently categorized as high-risk.
    • Patterns that are concentrated in a particular year may be related to seasonal, regional, or operational factors.

4. Accident Proportion by Phase of Flight (Last 10 Years - Pie Chart)

항공기 사고 파이차트 이미지
  • Interpretation: The percentage of incidents over the last 10 years is Landingis the highest, Takeoffand Cruisefollowed by The remaining phases have relatively low percentages.
  • Insights:
    • The landing and takeoff phases suggest the need to further strengthen accident prevention measures.
    • Cruise Incidents in stages still need to be noted, and causes such as technical issues (e.g. engine failure) need to be analyzed.

5. Monthly Accident Patterns by Phase of Flight (Line Chart)

항공기 사고 라인차트 이미지2
  • Interpretation: Landingand Takeoff phase, the number of accidents tends to increase during the summer months (June through August). This may be related to the increase in aircraft operations during the summer months.
  • Insights:
    • Increased air traffic during the summer months increases the likelihood of accidents.
    • Additional maintenance and training programs should be ramped up to reduce the seasonal impact.

6. Summary Statistics for Accidents by Phase of Flight

항공기 사고 요약 통계 이미지
  • Interpretation: Landing Stage has the highest average number of incidents (593.38), a large standard deviation (129.93), and high variability with a maximum value (472).
  • Insights:
    • The number of accidents during the landing phase varies, indicating that it is highly influenced by conditions (weather, pilot skill, etc.).
    • Takeoff (Takeoff) and adherence to standardized procedures during the landing phase are key to reducing accidents.

Comprehensive insights

Improved focus on landing and takeoff phases

  • The data clearly shows that accidents are concentrated during the landing and takeoff phases. To address this, pilots need to be better trained and aircraft health checks need to be more thorough.
  1. Need to analyze seasonality: Considering the increase in accidents during the summer months, seasonal precautions should be increased.
  2. Need to keep improving technology: Cruise Research and investment in solving technical problems on long flight segments, such as stages, is important.
  3. Dive into specific years/stages of data: It is necessary to analyze accidents concentrated in a particular year to examine aircraft models, operating procedures, and external factors.

Python Code Explained

Installing and importing libraries

!pip install kaggle -q # Install the Kaggle library
import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px

In this section, you will install and import the required libraries. Install the kaggle library to use the Kaggle API, and import the pandas, seaborn, matplotlib, and plotly libraries for data analysis and visualization.

Setting up the Kaggle API

os.environ['KAGGLE_CONFIG_DIR'] = '/content' # Set to current directory
!chmod 600 /content/kaggle.json Set # permissions

Set up environment variables to use the Kaggle API, and set permissions for the API key file (kaggle.json).

Downloading and loading data

!kaggle datasets download -d khsamaha/aviation-accident-database-synopses -p /content/aviation_data --unzip

file_path = "/content/aviation_data/AviationData.csv"
df = pd.read_csv(file_path, encoding='ISO-8859-1', low_memory=False)

Download and unzip the dataset using the Kaggle API. Then load the CSV file into a dataframe using pandas.

Data preprocessing

df.rename(columns={"Event Date": "Event_Date", "Broad.phase.of.flight": "Phase_of_Flight"}, inplace=True)
df['Event_Date'] = pd.to_datetime(df['Event_Date'], errors='coerce')
df['Year'] = df['Event_Date'].dt.year
df = df.dropna(subset=['Phase_of_Flight'])

Rename columns, convert date data to datetime format, add a 'Year' column, and remove rows with missing values.

Data aggregation

phase_counts = (
    df.groupby(['Phase_of_Flight', 'Year'])
    .size()
    .reset_index(name='count')
)

Aggregate the number of incidents by operational phase and year.

Python visualization

  1. Total number of incidents per flight phase (Bar charts)
  2. Annual accident trends by operational phase (Line graphs)
  3. Incident heatmap by year and operational phase
  4. Accident rates by operational phase over the last 10 years (interactive pie chart)
  5. Incident patterns by month (line graph)

For each visualization, choose the appropriate graph type and implement it using matplotlib, seaborn, or plotly.

Basic statistics output

summary_stats = (
    phase_counts.groupby('Phase_of_Flight')
    .agg({'count': ['mean', 'std', 'min', 'max']})
    .round(2)
)
print("\n=== Summary Statistics for Accidents by Phase of Flight ===")
print(summary_stats)

Calculate and output basic statistics (mean, standard deviation, minimum, maximum) for the number of incidents per flight phase.

Recapping - Mourning and Vigilance in the Jeju Air Crash

The Jeju Air crash is a heartbreaking aviation tragedy. It is right that the whole nation should mourn, and at the same time, we should thoroughly analyze the causes and take countermeasures. In addition, I think we all need to keep an eye on this tragedy so that it is not used for political purposes.

Utilizing tools like Python can provide insight into identifying risks and implementing solutions that can save lives. As we mourn this tragedy, we need the nation's attention to make our skies safer. We hope this analysis of aircraft accident data is a small step on that journey.

Similar Posts