%load_ext autoreload
%autoreload
import os
if not os.path.basename(os.getcwd()) == "datenguide-python":
os.chdir("..")
from datenguidepy.query_helper import get_all_regions, get_statistics
from datenguidepy import Query
import pandas as pd
import matplotlib
%matplotlib inline
pd.set_option('display.max_colwidth', 150)
# get the ID of Berlin by querying all states by name
get_all_regions().query("name == 'Berlin'")
# find out the name of the desired statistic
get_statistics().query('long_description.str.contains("Unfälle")', engine='python')
get_statistics().query('statistics.str.contains("AI1302")', engine = 'python')
q = Query.region('11')
f1 = q.add_field('AI1302')
f2 = q.add_field('AI1304')
f1.get_info()
f2.get_info()
results = q.results()
results
results.set_index('year')[['AI1302', 'AI1304']].plot()
import plotly.graph_objs as go
df = results.set_index('year')
fig = go.Figure()
fig.add_trace(
go.Scattergl(
x=df.index,
y=df['AI1302'],
mode="lines+markers",
name="AI1302",
)
)
fig.add_trace(
go.Scattergl(
x=df.index,
y=df['AI1304'],
mode="lines+markers",
name="AI1304",
)
)
fig.update_xaxes(title_text="Time")
fig.update_yaxes(title_text="Accidents")
fig.show()
Both, accidents per 10.000 inhabitants (AI1302), as well as killed people per 100.000 inhabitants (AI1304) decreased significantly especially between 1995 and 2005.