from matplotlib.pylab import rcParams

import matplotlib.pylab as plt

import pandas as pd

country = 'Philippines'

df = pd.read_csv('../input/attacks_data_UTF8.csv', encoding='latin1', parse_dates=['Date'], infer_datetime_format=True, index_col=1)

if country is not None:
    dfc = df.loc[df['Country'] == country]
else:
    dfc = df

country_rank = df.Country.value_counts().rank(numeric_only=True, ascending=False).loc[country]
country_attacks = df.Country.value_counts()[country]
country_killed = dfc.Killed.sum()
country_injured = dfc.Injured.sum()

dfc.groupby('City').sum()[['Victims', 'Killed', 'Injured']].sort_values(by='Victims', ascending=0).plot(kind='bar', figsize=(17, 7), subplots=True)

most_victim = dfc.sort_values(by='Victims', ascending=False).head(1)
most_killed = dfc.sort_values(by='Killed', ascending=False).head(1)
most_injuries = dfc.sort_values(by='Injured', ascending=False).head(1)

dfc.groupby(dfc.index.year).sum()[['Victims', 'Killed', 'Injured']].sort_values(by='Victims', ascending=0).plot(kind='bar', figsize=(17, 7), subplots=False)

killedbyday = dfc.groupby([dfc.index.map(lambda x: x.weekday), dfc.index.year], sort=True).agg({'Killed': 'sum'})
rcParams['figure.figsize'] = (20, 10)

killedbymonth = dfc.groupby([dfc.index.map(lambda x: x.month), dfc.index.year], sort=True).agg({'Killed': 'sum'})
rcParams['figure.figsize'] = (20, 10)
killedbymonth.unstack(level=0).plot(kind='bar', subplots=False)
killedbymonth.unstack(level=1).plot(kind='bar', subplots=False)