import pandas as ps

import string

fileR = ps.read_csv('../input/3-Airplane_Crashes_Since_1908.txt', sep=',')

fileR['Date'] = ps.to_datetime(fileR['Date'])
fileR['year'] = fileR['Date'].dt.year
fileR['month'] = fileR['Date'].dt.month
fileR['day'] = fileR['Date'].dt.day
sub_years = [1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010]
years_legend = list(string.ascii_letters[:len(sub_years)])
fileR['year_group'] = ''
for i in range(0, len(sub_years) - 1):
    fileR.loc[(sub_years[i + 1] > fileR['year']) & (fileR['year'] >= sub_years[i]), ['year_group']] = years_legend[i]

subfile2 = fileR[['Aboard', 'Fatalities', 'year', 'Operator', 'Type']].groupby('Operator').sum()
subfile2['survived'] = subfile2['Aboard'] - subfile2['Fatalities']
subfile2['percentageSurvived'] = subfile2['survived'] / subfile2['Aboard']
subfile3 = subfile2[subfile2['year'] > max(fileR['year'])]

highSurvive = subfile3.sort_values(by='percentageSurvived', ascending=False)[:20]
highSurvive

highSurvive['percentageSurvived'].plot(kind='bar', color='g', fontsize=14, title='Operators with high percentage of survivers')