Created
January 5, 2020 13:52
-
-
Save niftycode/500ac7cb2dd949dbbe6388ecc9346bc1 to your computer and use it in GitHub Desktop.
The bankruptcies in Kiel, Germany
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
''' | |
Unternehmensinsolvenzen in Kiel | |
The data is provided by the Open Data Portal Schleswig-Holstein, Germany | |
https://opendata.schleswig-holstein.de/dataset/unternehmensinsolvenzen-in-kiel | |
Version: 1.0 | |
Python 3.8 | |
Date created: 05.01.2020 | |
''' | |
import io | |
import requests | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
CSV_URL = 'https://www.kiel.de/opendata/kiel_wirtschaft_arbeit_unternehmensinsolvenzen.csv' | |
# Fetch the data | |
csv_data = requests.get(CSV_URL).content | |
# Create a dataframe | |
df = pd.read_csv(io.StringIO(csv_data.decode('latin1')), sep=';') | |
# Use a subplot | |
fig, ax = plt.subplots() | |
# Print the dataframe's head (five rows) | |
print(df.head()) | |
# Drop not available data | |
df_cleaned = df.dropna(how='all') | |
# x = Jahr as uint16 / y = Insolvenzen | |
df_years = df_cleaned['Jahr'].astype(np.uint16) | |
x = df_years.values | |
y = df_cleaned['Insolvenzen'].values | |
# Title and labels | |
plt.title("Kiel - Unternehmensinsolvenzen", size="x-large") | |
plt.ylabel("Anzahl", size="x-large") | |
plt.xlabel("Jahr", size="x-large") | |
plt.plot(y, "r*-", markersize=6, linewidth=1, color='b') | |
ax.set_xticks(range(len(x))) | |
ax.set_xticklabels(x, rotation='vertical') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment