Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use Kiel's OpenData to visualize traffic accidents with Python and Pandas
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Traffic Accidents in Kiel, Germany
Python 3.6
last edited: 19/10/2017
The data is provided by the City of Kiel, Germany
import requests
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import io
CSV_URL = ''
csv_data = requests.get(CSV_URL).content
df = pd.read_csv(io.StringIO(csv_data.decode('latin1')), sep=';')
fig, ax = plt.subplots()
df_cleaned = df.dropna(how='all')
df_years = df_cleaned['Jahr'].astype(np.uint16)
x = df_years.values
y = df_cleaned['Unfälle'].values
print("Jahr = ", x)
plt.title("Traffic Accidents in Kiel", size="x-large")
plt.ylabel("Quantity", size="x-large")
plt.xlabel("Year", size="x-large")
plt.plot(y, "r*-", markersize=6, linewidth=1, color='b', label="Traffic Accidents")
plt.legend(loc=(0.4, 0.8))
ax.set_xticklabels(x, rotation='vertical')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.