Plane Crashes Rise Then Fall, Overall Avg. Pct. Fatalities at 83.4% (1908-2009)

crashes_by_yrThis dataset comprises airplane crashes from military, private, and commercial airlines from around the world from 1908 to 2009.  The purpose of this project was to further practice cleaning, transforming, analyzing, and visualizing data in Python.  I did discover a few interesting things about airplane crashes in the process.  For instance, after the Wright brothers successfully flew their Flyer I in December 17, 1903, we see an upward trend in plane crashes, undoubtedly due to the increase in plane manufacturing.  This upward trend continued until 1972 (peaked at 142 crashes), after which we see a steady downward trend.  You’d be mistaken, however, if you thought this was due to a decrease in plane travel.  Quite the contrary.  Plane travel is fastly growing [1] [2].  This decrease in plane crashes is clearly due to improved design and safety measures.

Plotting the total fatalities (for those onboard the plane and those on the ground) lets us see just how anomalistic the 9/11 terrorist attack was, as we see a large spike of fatalities for 2001.

deaths_by_yr

Out of the 5,211 crashes represented in the data, 889 (17.1%) had less than 50% fatalities, 4,320 (82.9%) had over 50% fatalities, and 3,483 (66.8%) had 100% fatalities. The overall average percent fatal is 83.4%. This only pertains to those onboard the plane.  The following visual helps you to see this dispersion more vividly but the data is restricted to 1970-2009.

 

pct_fatal_yr_1970-2009

(larger view)

Note the blotches of orange at the top (100%).  Displaying the distribution of percent fatalities as a histogram helps you to see the frequency of crashes having 100% fatalities more clearly.

pct_fatal_dist_1970-2009

Keep in mind that these statistics include military, private, and commercial planes. There was no easy way to categorize the manufacturers as either military, private, or commercial, as not all military manufacturers had “military” in their name, plus some of the manufacturers fall into more than one category. For that reason, and due to there being about 290 manufacturers, I decided not to attempt to categorize them, though we would likely see some statistical variation if broken out by category. However, for the primary purpose of this project, to further develop my Python skills, this was not necessary.

The entire coding process is provided below.


 

# Setup environment
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
In [274]:
# Read in data and summarize
planes = pd.read_csv('Airplane_Crashes_and_Fatalities_Since_1908.csv')
planes.head()
Out[274]:
Date Time Location Operator Flight # Route Type Registration cn/In Aboard Fatalities Ground Summary
0 09/17/1908 17:18 Fort Myer, Virginia Military – U.S. Army NaN Demonstration Wright Flyer III NaN 1 2.0 1.0 0.0 During a demonstration flight, a U.S. Army fly…
1 07/12/1912 06:30 AtlantiCity, New Jersey Military – U.S. Navy NaN Test flight Dirigible NaN NaN 5.0 5.0 0.0 First U.S. dirigible Akron exploded just offsh…
2 08/06/1913 NaN Victoria, British Columbia, Canada Private NaN Curtiss seaplane NaN NaN 1.0 1.0 0.0 The first fatal airplane accident in Canada oc…
3 09/09/1913 18:30 Over the North Sea Military – German Navy NaN NaN Zeppelin L-1 (airship) NaN NaN 20.0 14.0 0.0 The airship flew into a thunderstorm and encou…
4 10/17/1913 10:30 Near Johannisthal, Germany Military – German Navy NaN NaN Zeppelin L-2 (airship) NaN NaN 30.0 30.0 0.0 Hydrogen gas which was being vented was sucked…
In [275]:
planes.shape
Out[275]:
(5268, 13)
In [276]:
planes.dtypes
Out[276]:
Date             object
Time             object
Location         object
Operator         object
Flight #         object
Route            object
Type             object
Registration     object
cn/In            object
Aboard          float64
Fatalities      float64
Ground          float64
Summary          object
dtype: object
In [277]:
# Are there any missing data?
planes.isnull().sum()
Out[277]:
Date               0
Time            2219
Location          20
Operator          18
Flight #        4199
Route           1706
Type              27
Registration     335
cn/In           1228
Aboard            22
Fatalities        12
Ground            22
Summary          390
dtype: int64

Missing Data

This dataset contains a lot of missing data. However, I am primarily concerned with “Type”, “Aboard”, “Fatalities”, and “Ground”. These fields do not have very many nulls. Let’s remove all rows that contain nulls in these columns.

In [278]:
planes.dropna(subset=['Type','Aboard','Fatalities','Ground'], inplace=True)
planes.isnull().sum()
Out[278]:
Date               0
Time            2166
Location          19
Operator          12
Flight #        4144
Route           1667
Type               0
Registration     310
cn/In           1186
Aboard             0
Fatalities         0
Ground             0
Summary          374
dtype: int64
In [279]:
planes.shape
Out[279]:
(5211, 13)
In [280]:
# Convert Date, which is currently an object, to datetime and create year and month columns from it
planes['Date'] = pd.to_datetime(planes['Date'])
planes['Year'], planes['Month'] = planes['Date'].dt.year, planes['Date'].dt.month
planes.head()
Out[280]:
Date Time Location Operator Flight # Route Type Registration cn/In Aboard Fatalities Ground Summary Year Month
0 1908-09-17 17:18 Fort Myer, Virginia Military – U.S. Army NaN Demonstration Wright Flyer III NaN 1 2.0 1.0 0.0 During a demonstration flight, a U.S. Army fly… 1908 9
1 1912-07-12 06:30 AtlantiCity, New Jersey Military – U.S. Navy NaN Test flight Dirigible NaN NaN 5.0 5.0 0.0 First U.S. dirigible Akron exploded just offsh… 1912 7
2 1913-08-06 NaN Victoria, British Columbia, Canada Private NaN Curtiss seaplane NaN NaN 1.0 1.0 0.0 The first fatal airplane accident in Canada oc… 1913 8
3 1913-09-09 18:30 Over the North Sea Military – German Navy NaN NaN Zeppelin L-1 (airship) NaN NaN 20.0 14.0 0.0 The airship flew into a thunderstorm and encou… 1913 9
4 1913-10-17 10:30 Near Johannisthal, Germany Military – German Navy NaN NaN Zeppelin L-2 (airship) NaN NaN 30.0 30.0 0.0 Hydrogen gas which was being vented was sucked… 1913 10
In [281]:
# Only keep the columns that are pertinent to this analysis
keep_cols = ['Date','Year','Month','Location','Operator','Type','Aboard','Fatalities','Ground','Summary']
planes = planes[keep_cols]
planes.columns
Out[281]:
Index(['Date', 'Year', 'Month', 'Location', 'Operator', 'Type', 'Aboard',
       'Fatalities', 'Ground', 'Summary'],
      dtype='object')
In [282]:
# Convert Aboard and Fatalities to int
planes['Aboard'] = planes['Aboard'].astype(int)
planes['Fatalities'] = planes['Fatalities'].astype(int)
planes['Ground'] = planes['Ground'].astype(int)
planes.dtypes
Out[282]:
Date          datetime64[ns]
Year                   int64
Month                  int64
Location              object
Operator              object
Type                  object
Aboard                 int32
Fatalities             int32
Ground                 int32
Summary               object
dtype: object
In [283]:
# Total crashes by year
crashes_by_yr = planes.pivot_table(values='Operator', index='Year', aggfunc='count') # Operator is used to count instances
In [284]:
# Store max number of crashes by year
import numpy as np
max_crashes = np.asscalar(max(crashes_by_yr.values))
crashes_by_yr[crashes_by_yr.values==max_crashes]
Out[284]:
Operator
Year
1972 104
In [285]:
# plot line chart of total crashes by year

mycolor = '#cc5500'

fig = plt.figure()
crashes_by_yr.plot(legend=False, color=mycolor)
plt.plot(1972, 104, marker='o', markersize=4, color=mycolor)
plt.plot([1903,1903], [0,85], lw=1, color='gray')
sns.despine()
plt.title('Total Plane Crashes by Year', loc='left', fontweight='bold', y=1.02)
plt.xticks(range(1905,2015,10))
plt.ylabel('Crashes')
plt.text(1969, 108, max_crashes)
plt.text(1903, 90, 'Wright brothers\nsuccessfully fly their\nFlyer I aircraft (1903)', fontsize=9)
plt.tight_layout()
plt.savefig('crashes_by_yr.png')

crashes_by_yr

Crashes Climb Then Fall (1908-2009)

After the Wright brothers successfully flew their Flyer I in December 17, 1903, improving the design of planes took off. This is likely why we see this upward trend in plane crashes from 1908-1972. What may be comforting to many, however, is that this shifted to a downward trend after it peaked in 1972 at 142 crashes. You’d be mistaken, however, if you thought this was due to a decrease in airplane travel. Quite the contrary. Airplane travel is fastly growing [1] [2]. This decrease in airplane crashes is clearly due to improved design and safety measures.

In [286]:
# Total deaths by year
planes['Ttl_Deaths'] = planes['Fatalities'] + planes['Ground']
deaths_by_yr = planes.pivot_table(values='Ttl_Deaths', index='Year', aggfunc='sum')
In [287]:
# Store max number of deaths by year
max_deaths = np.asscalar(max(deaths_by_yr.values))
deaths_by_yr[deaths_by_yr.values==max_deaths]
Out[287]:
Ttl_Deaths
Year
2001 7039
In [288]:
# That number seems too high, even with the thousands that died during the terrorist attacks on 9/11.
# Let's filter down to 9/11/2001
planes[planes['Date']=='09-11-2001']
Out[288]:
Date Year Month Location Operator Type Aboard Fatalities Ground Summary Ttl_Deaths
4801 2001-09-11 2001 9 Shanksville, Pennsylvania United Air Lines Boeing B-757-222 44 44 0 The aircraft was hijacked after taking off fro… 44
4802 2001-09-11 2001 9 Arlington, Virginia. American Airlines Boeing B-757-223 64 64 125 The aircraft was hijacked after taking off fro… 189
4803 2001-09-11 2001 9 New York City, New York American Airlines Boeing 767-223ER 92 92 2750 The aircraft was hijacked shortly after it lef… 2842
4804 2001-09-11 2001 9 New York City, New York United Air Lines Boeing B-767-222 65 65 2750 The aircraft was hijacked shortly after it lef… 2815
In [289]:
# It looks like the ground deaths of 2,750 were counted twice.
# Replace one of them with a 0 and recalculate Ttl_Deaths
planes.loc[4803, 'Ground'] = 0
planes['Ttl_Deaths'] = planes['Fatalities'] + planes['Ground']
planes[planes['Date']=='09-11-2001']
Out[289]:
Date Year Month Location Operator Type Aboard Fatalities Ground Summary Ttl_Deaths
4801 2001-09-11 2001 9 Shanksville, Pennsylvania United Air Lines Boeing B-757-222 44 44 0 The aircraft was hijacked after taking off fro… 44
4802 2001-09-11 2001 9 Arlington, Virginia. American Airlines Boeing B-757-223 64 64 125 The aircraft was hijacked after taking off fro… 189
4803 2001-09-11 2001 9 New York City, New York American Airlines Boeing 767-223ER 92 92 0 The aircraft was hijacked shortly after it lef… 92
4804 2001-09-11 2001 9 New York City, New York United Air Lines Boeing B-767-222 65 65 2750 The aircraft was hijacked shortly after it lef… 2815
In [290]:
# Recalculate total deaths by year
deaths_by_yr = planes.pivot_table(values='Ttl_Deaths', index='Year', aggfunc='sum')
max_deaths = np.asscalar(max(deaths_by_yr.values))
deaths_by_yr[deaths_by_yr.values==max_deaths]
Out[290]:
Ttl_Deaths
Year
2001 4289
In [291]:
# Plot total deaths by year
fig = plt.figure()
deaths_by_yr.plot(legend=False, color=mycolor)
plt.plot(2001, 4289, marker='o', markersize=4, color=mycolor)
plt.plot([1990,2000],[4100,4250], color='gray', lw=1)
sns.despine()
plt.title('Total Air & Ground Deaths by Year', loc='left', fontweight='bold', y=1.02)
plt.ylabel('Deaths')
plt.xticks(range(1905,2015,10))
plt.text(1925, 3800, '(2001): The terrorist attacks on 9/11 make up\nabout 3,000 deaths for this year.', fontsize=9)
plt.tight_layout()
plt.savefig('deaths_by_yr.png')

deaths_by_yr

9/11 and the Twin Towers

September 11, 2001, simply referred to as 9/11, marks one of the most tragic days for Americans. About 3,000 people perished when terrorists flew two planes into the Twin Towers (the centerpieces of the World Trade Center complex). The graph makes it vivid just how tragic this event was. If this data was plotted, without having any knowledge of this historical event, one would think there was an error in the data.

In [311]:
# Create a manufacturer column by splitting Type and keeping the first word
planes['Manufacturer'] = planes['Type'].str.split(' ', 1).str.get(0)
planes['Manufacturer'].unique()
Out[311]:
array(['Wright', 'Dirigible', 'Curtiss', 'Zeppelin', 'Schutte-Lanz',
       'Super', 'Airship', 'De', 'Armstrong-Whitworth', 'Junkers',
       'Salmson', 'Breguet', 'Handley', 'Royal', 'Potez', 'Bristol', 'de',
       'Vickers', 'Bleriot', 'Lioré-et-Olivier', 'Farman', 'Blériot',
       'Fokker', 'Caudron', 'Sikorsky', 'Ryan', 'Douglas', 'SPCA', 'BFW',
       'Dornier', 'Fairchild', 'Latécoère', 'Latecoere', 'Boeing',
       'Rohrbach', 'Ford', 'AEGK', 'Hamilton', 'Travel', 'Stearman',
       'CMASA', 'Cams', 'Domier', 'Lockheed', 'Kalinin', 'Pitcairn',
       'Short', 'Loening', 'Liore', 'Bernard', 'Arado', 'Sabca',
       'Messerschmitt', 'Desoutter', 'Avro', 'Lasco', 'Heinkel',
       'Stinson', 'CAMS', 'Northrop', 'Liore-et-Olivier', 'Armstrong',
       'Goodyear-Zeppelin', 'Pitcairns', 'Focke-Wulf', 'Dewoitine',
       'Wibault', 'Consolidated', 'Tupolev', 'General', 'Waco,',
       'Savoia-Marchetti', 'Vultee', 'Dormier', 'OFM', 'Saro', 'Boulton',
       'Blackburn', 'Antonov', 'V6', 'Savoia', 'Curtiss-Wright',
       'Armstrong-Withworth', 'Martin', 'Macchi', 'Savbia-Marchetti',
       'Nakajima', 'Koolhoven', 'Mitsubishi', 'Bloch', 'deHavilland',
       'Siebel', 'Sirkorsky', 'B-17C', 'Pilgrim', 'C-47', 'UC-64A',
       'B17G', 'North', 'Faucett', 'Five', 'PBY4-2', 'Fairey', 'AAC-1',
       'Lisunov', 'Fiat', 'FIAT', 'Convair', 'DC-2-243', 'SNCASE',
       'Cessna', 'Ilyushin', 'F-88', 'Canadair', 'Aero', 'CF-100',
       'Airspeed', 'Saab', 'Beechcraft', 'Nord', 'Sud', 'Goodyear', 'MD',
       'Avia', 'McDonnell', 'Sud-Aviation', 'Silver', 'Grumman',
       'Channel', 'Bell', 'Beech', 'Piper', 'H-21B', 'VEB',
       'Kaiser-Fraser', 'Tupelov', 'BAC', 'Curtis', 'Caravelle', 'Hughes',
       'EC-121H', 'Transportes', 'Learjet', 'Chance', 'NAMC-YS-11-111',
       'PBY-5A', 'S2F-1', 'AT', 'Cessnea', 'Hiller', 'Brantly', 'MiG-15',
       'Piaggio', 'Fairchild-Hiller', 'Hawker', 'Britten-Norman',
       'Pilatus', 'LTVF-8J', 'Aerospatiale', 'Gates', 'NAMC', 'Yakovlev',
       'HAL-748-224', 'Swearingen', 'MDonnell', 'MBB', 'Shorts', 'F-86',
       'Volpar', 'Norman', 'Transall', 'Brittonnorman', 'Robertson',
       'Brittonorman', 'Embraer', 'NA', 'Lear', 'Bellanca', 'IAI', 'GAF',
       'Airbus', 'L-100-20', 'Pipper', 'Helo', 'Sikorksky', 'SNIAS',
       'Aerostar', 'Evangel', 'British', 'PS-1', 'Britten', 'Soloy',
       'Let', 'Hindustan', 'LET', 'CASA', 'Dassault-Breguet', 'Hadley',
       'Westland', 'LeT', 'Arava', 'Mil', 'Kawasaki', 'PT-LCN',
       'McDonnel', 'Aerospeciale', 'PA-23-250', 'Gulfstream',
       'HS-125-700B', 'CH-53D', 'Sepecat', 'Dassault', 'Howard', 'Casa',
       'Enstrom', 'Boeing-Vertol', 'F-4C', 'Rockwell', 'Military',
       'Partenavia', 'Aermacchi', 'BAe-748', 'Mitsubish', 'Aérospatiale',
       'Agusta', 'DHC-5', 'MiG-23', 'IPTN', 'Learjet35A',
       'Hawker-Siddeley', 'BeechJet', 'BAe', 'Shaanxi', 'Helicopter,',
       'DHC-6', 'Yunshuji', 'Israel', 'GD', 'ATR-72-212', 'Pel', 'Swear.',
       'ConvairCV-440', 'Harbin', 'Aviation', 'Rutan', 'Grummand',
       'Saab340B', 'Xian', 'Eurocopter', 'DC-3-65TP', 'Burgess',
       'AirbusA310-304', 'MD-87', 'EMB', 'BAE', 'MH-47', 'Shrike', 'Mi-8',
       'Mi-17', 'PA-', 'Sukhoi', 'Iluyshin', 'PA-34-220T', 'ATR', 'UH-60',
       'Aérospatiale/Aeritalia', 'Embraer-110', 'Illyushin', 'CH-47',
       'PZL-MieleAN-2R', 'Mi-8MTV-1', 'CH-47D', 'Pilatus-Britten', 'Bae',
       'Bambardier', 'McDonnell-Douglas', 'HBB', 'Cesna', 'PZL-MieleM28',
       'Black', 'CH53E', 'Let-410UVP-E', 'ATR-72-202', 'KJ-2000',
       'Ilushin', 'Mi', 'ATR-42-300', 'Ilysushin', 'Bandeirante',
       'Bombardier', 'Mi-35'], dtype=object)
In [293]:
# Not all manufacturers may have the same capitalization (e.g. 'FIAT', 'Fiat').
# Convert all to uppercase to ensure they can be grouped properly
planes['Manufacturer'] = planes['Manufacturer'].str.upper()
planes['Manufacturer'][0:10]
Out[293]:
0          WRIGHT
1       DIRIGIBLE
2         CURTISS
3        ZEPPELIN
4        ZEPPELIN
5        ZEPPELIN
6        ZEPPELIN
7    SCHUTTE-LANZ
8        ZEPPELIN
9        ZEPPELIN
Name: Manufacturer, dtype: object
In [294]:
# Select common manufacturers
manf_list = ['DIRIGIBLE','LOCKHEED','ZEPPELIN','BOEING','FORD','FIAT','AIRBUS','SAAB','GOODYEAR','DOUGLAS','ROCKWELL','KAWASAKI','CESSNA']
planes_sub = planes[planes['Manufacturer'].isin(manf_list)]
planes_sub.head()

# Group crashes by manufacturer and plot
crashes_by_manf = planes_sub.pivot_table(values='Operator', index='Manufacturer', aggfunc='count') # Operator used to count instances
crashes_by_manf = crashes_by_manf.sort_values(by='Operator')
crashes_by_manf.plot.barh(legend=False, color=mycolor, width=0.7)
sns.despine()
plt.xlabel='Crashes'
plt.title('Total Crashes by Manufacturer', loc='left', fontweight='bold', y=1.02)
plt.tight_layout()
plt.savefig('crashes_by_manf.png')

crashes_by_manf

In [295]:
# Plot crashes by year for the top three manufacturers with the most crashes
crashes_by_manf_3 = planes_sub[planes_sub['Manufacturer'].isin(['DOUGLAS','BOEING','LOCKHEED','CESSNA'])]
crashes_by_manf_3 = crashes_by_manf_3.pivot_table(values='Operator', index=['Manufacturer','Year'], aggfunc='count')
douglas_crash = crashes_by_manf_3.loc['DOUGLAS']
boeing_crash = crashes_by_manf_3.loc['BOEING']
lockheed_crash = crashes_by_manf_3.loc['LOCKHEED']
cessna_crash = crashes_by_manf_3.loc['CESSNA']
fig = plt.figure()
plt.plot(douglas_crash)
plt.plot(boeing_crash)
plt.plot(lockheed_crash)
plt.plot(cessna_crash)
plt.legend(['Douglas','Boeing','Lockheed','Cessna'], frameon=False)
plt.xticks(range(1925,2015,10))
plt.title('Top Manufacturers with Most Crashes', loc='left', fontweight='bold', y=1.02)
sns.despine()
plt.tight_layout()
plt.show()

manf_crashes

In [296]:
# Group crashes by month
crashes_by_mo = planes.pivot_table(values='Operator', index='Month', aggfunc='count') # Operater used to count instances
crashes_by_mo.plot.bar(legend=False, color=mycolor, rot=360)
sns.despine()
plt.title('Total Crashes by Month', loc='left', fontweight='bold', y=1.02)
plt.savefig('crashes_by_month.png')

crashes_by_month

# Create a Pct_Fatal column that divides Fatalities by Aboard
planes['Pct_Fatal'] = round(planes['Fatalities'] / planes['Aboard'], 2)
planes.head(10)
Out[297]:
Date Year Month Location Operator Type Aboard Fatalities Ground Summary Ttl_Deaths Manufacturer Pct_Fatal
0 1908-09-17 1908 9 Fort Myer, Virginia Military – U.S. Army Wright Flyer III 2 1 0 During a demonstration flight, a U.S. Army fly… 1 WRIGHT 0.50
1 1912-07-12 1912 7 AtlantiCity, New Jersey Military – U.S. Navy Dirigible 5 5 0 First U.S. dirigible Akron exploded just offsh… 5 DIRIGIBLE 1.00
2 1913-08-06 1913 8 Victoria, British Columbia, Canada Private Curtiss seaplane 1 1 0 The first fatal airplane accident in Canada oc… 1 CURTISS 1.00
3 1913-09-09 1913 9 Over the North Sea Military – German Navy Zeppelin L-1 (airship) 20 14 0 The airship flew into a thunderstorm and encou… 14 ZEPPELIN 0.70
4 1913-10-17 1913 10 Near Johannisthal, Germany Military – German Navy Zeppelin L-2 (airship) 30 30 0 Hydrogen gas which was being vented was sucked… 30 ZEPPELIN 1.00
5 1915-03-05 1915 3 Tienen, Belgium Military – German Navy Zeppelin L-8 (airship) 41 21 0 Crashed into trees while attempting to land af… 21 ZEPPELIN 0.51
6 1915-09-03 1915 9 Off Cuxhaven, Germany Military – German Navy Zeppelin L-10 (airship) 19 19 0 Exploded and burned near Neuwerk Island, when… 19 ZEPPELIN 1.00
7 1916-07-28 1916 7 Near Jambol, Bulgeria Military – German Army Schutte-Lanz S-L-10 (airship) 20 20 0 Crashed near the Black Sea, cause unknown. 20 SCHUTTE-LANZ 1.00
8 1916-09-24 1916 9 Billericay, England Military – German Navy Zeppelin L-32 (airship) 22 22 0 Shot down by British aircraft crashing in flames. 22 ZEPPELIN 1.00
9 1916-10-01 1916 10 Potters Bar, England Military – German Navy Zeppelin L-31 (airship) 19 19 0 Shot down in flames by the British 39th Home D… 19 ZEPPELIN 1.00
In [298]:
# Plot avg Pct_Fatal by year; restrict data to 1970-2009
planes_1970_2009 = planes[planes['Year']>=1970]
overall_avg_pct_fatal = round(planes['Pct_Fatal'].mean(), 4) * 100
avg_pct_fatal_yr = planes_1970_2009.pivot_table(values='Pct_Fatal', index='Year', aggfunc='mean')
avg_pct_fatal_yr.plot.bar(figsize=(10,4), rot=45, legend=False, color=mycolor)
plt.ylabel('')
plt.title('What is the avg. pct. of fatalities by year?', loc='left', fontweight='bold', y=1.02)
sns.despine()
overall_avg_pct_fatal
Out[299]:
83.42
In [300]:
fig = plt.subplots(figsize=(20,6))
sns.stripplot(data=planes_1970_2009, x='Year', y='Pct_Fatal', jitter=0.25, color=mycolor, alpha=0.7, size=4)
sns.despine(left=True, top=True, right=True, bottom=True)
plt.axhline(0.5, color='gray', lw=0.5)
plt.title('Pct. Fatal (Onboard) Dispersion by Year (1970-2009)', loc='left', fontweight='bold', y=1.02)
plt.savefig('pct_fatal_yr_1970-2009.png', dpi=500)

pct_fatal_yr_1970-2009

fatal_less_50 = len(planes[planes['Pct_Fatal']<=0.5])
pct_less_50 = round(fatal_less_50 / len(planes), 4) * 100
fatal_greater_50 = len(planes[planes['Pct_Fatal']>0.5])
pct_greater_50 = round(fatal_greater_50 / len(planes), 4) * 100
fatal_equal_100 = len(planes[planes['Pct_Fatal']==1])
pct_100 = round(fatal_equal_100 / len(planes), 4) * 100
print(fatal_less_50)
print(pct_less_50)
print(fatal_greater_50)
print(pct_greater_50)
print(fatal_equal_100)
print(pct_100)
889
17.06
4320
82.89999999999999
3483
66.84
In [302]:
planes_1970_2009['Pct_Fatal'].plot.hist(color=mycolor, edgecolor='white', lw=0.5)
sns.despine(left=True, top=True, right=True, bottom=True)
plt.title('Pct. Fatal Distribution (1970-2009)', loc='left', fontweight='bold', y=1.02)
plt.tick_params(which='both', bottom=False, left=False)
plt.tight_layout()
plt.savefig('pct_fatal_dist_1970-2009.png')

pct_fatal_dist_1970-2009

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s