application_vnd.jupyter.stderr_output_1.png
from plotly.offline import iplot, init_notebook_mode

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import plotly.graph_objs as go

import numpy as np
import pandas as pd
pd.options.mode.chained_assignment = None
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected=True)
terror_data = pd.read_csv('../input/globalterrorismdb_0616dist.csv', encoding='ISO-8859-1', usecols=[0, 1, 2, 3, 8, 11, 13, 14, 35, 84, 100, 103])
terror_data = terror_data.rename(columns={'eventid': 'id', 'iyear': 'year', 'imonth': 'month', 'iday': 'day', 'country_txt': 'country', 'provstate': 'state', 'targtype1_txt': 'target', 'weaptype1_txt': 'weapon', 'nkill': 'fatalities', 'nwound': 'injuries'})
terror_data['fatalities'] = terror_data['fatalities'].fillna(0).astype(int)
terror_data['injuries'] = terror_data['injuries'].fillna(0).astype(int)
attacks_france = terror_data[terror_data.country == 'France']

terror_peryear = np.asarray(attacks_france.groupby('year').year.count())
terror_years = np.arange(1972, 2016)
terror_years = np.delete(terror_years, [23])
trace = [go.Scatter(x=terror_years, y=terror_peryear, mode='lines', line=dict(color='rgb(240, 140, 45)', width=3))]
layout = go.Layout(title='Terrorist Attacks by Year in France (1970-2015)', xaxis=dict(rangeslider=dict(thickness=0.05), showline=True, showgrid=False), yaxis=dict(range=[0.1, 425], showline=True, showgrid=False))
figure = dict(data=trace, layout=layout)

attacks_france['text'] = attacks_france['date'].dt.strftime('%B %-d, %Y') + '<br>' + attacks_france['fatalities'].astype(str) + ' Killed, ' + attacks_france['injuries'].astype(str) + ' Injured'
fatality = dict(type='scattergeo', locationmode='USA-states', lon=attacks_france[attacks_france.fatalities > 0]['longitude'], lat=attacks_france[attacks_france.fatalities > 0]['latitude'], text=attacks_france[attacks_france.fatalities > 0]['text'], mode='markers', name='Fatalities', hoverinfo='text+name', marker=dict(size=attacks_france[attacks_france.fatalities > 0]['fatalities'] ** 0.255 * 8, opacity=0.95, color='rgb(240, 140, 45)'))
injury = dict(type='scattergeo', locationmode='USA-states', lon=attacks_france[attacks_france.fatalities == 0]['longitude'], lat=attacks_france[attacks_france.fatalities == 0]['latitude'], text=attacks_france[attacks_france.fatalities == 0]['text'], mode='markers', name='Injuries', hoverinfo='text+name', marker=dict(size=(attacks_france[attacks_france.fatalities == 0]['injuries'] + 1) ** 0.245 * 8, opacity=0.85, color='rgb(20, 150, 187)'))
layout = dict(title='Terrorist Attacks by Latitude/Longitude in France (1970-2015)', showlegend=True, legend=dict(x=0.85, y=0.4), geo=dict(scope='europe', projection=dict(type='albers usa'), showland=True, landcolor='rgb(250, 250, 250)', subunitwidth=1, subunitcolor='rgb(217, 217, 217)', countrywidth=1, countrycolor='rgb(217, 217, 217)', showlakes=True, lakecolor='rgb(255, 255, 255)'))
data = [fatality, injury]
figure = dict(data=data, layout=layout)
iplot(figure)