Skip to content

Instantly share code, notes, and snippets.

@niftycode
Created February 1, 2021 10:10
Show Gist options
  • Save niftycode/059b5f27daaa397867a4ae5d39899a4a to your computer and use it in GitHub Desktop.
Save niftycode/059b5f27daaa397867a4ae5d39899a4a to your computer and use it in GitHub Desktop.
Use pandas and matplotlib to show the passenger numbers in the port of Kiel
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Passengers - Kiel Harbour (1988-2019)
The data is provided by the City of Kiel, Germany
https://www.kiel.de/opendata/kiel_transport_verkehr_hafen_passagiere_insgesamt.csv
Version: 1.0
Python 3.8+
Date created: February 1st, 2021
'''
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_transport_verkehr_hafen_passagiere_insgesamt.csv'
csv_data = requests.get(CSV_URL).content
df = pd.read_csv(io.StringIO(csv_data.decode('utf-8')), sep=';')
# Show first 5 rows
# print(df.head())
# Create a subplot
fig, ax = plt.subplots()
df_cleaned = df.dropna(how='all')
# Unsigned integer (0 to 65535)
df_years = df_cleaned['Jahr'].astype(np.uint16)
x = df_years.values
y = df_cleaned['im Kreuzfahrverkehr'].values
plt.title("Kiel - Passagierzahlen (Kreuzfahrverkehr)", size="x-large")
plt.ylabel("Passagiere (in Tausend)", 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