We use the data from Statistisches Bundesamt (Destatis)
# Import Modules
import matplotlib.pyplot as plt
import pandas as pd
# Only use when the 'schwarzerwolf.mplstyle' has been downloaded and placed in the correct directory.
# For Debian Stretch the directory is: /usr/share/matplotlib/mpl-data/stylelib
plt.style.use('schwarzerwolf')
# Load the Data / The path must of course be adapted to your own circumstances
df = pd.read_csv('./data/Statistisches_Bundesamt/Population/12411-0007.csv',
engine='python', sep=';', header=8, skipfooter=7)
# Only takes the 'Total' data from the 'Age' column
df2 = df[df['Age'] == 'Total']
# Sets 'Date' as index
df2.index = df2['Date']
# Removes the 'Date' and 'Age'
df2 = df2.drop(['Date', 'Age'], axis=1)
# Creates a new 'DataFrame'.
df3 = pd.DataFrame()
# The values are divided for better visibility
for i, value in enumerate(df2.keys()):
df3 = df3.append(df2[value] / 1000000)
# The data are transposed to the correct representation
df3 = df3.T
# Plot / Labeling / Copyright
df3.plot(title='Population in Germany')
plt.ylabel('Population in Millions')
plt.xlabel('\nDatenquelle: Statistisches Bundesamt (Destatis), Genesis-Online, Abrufdatum 2017-08-30; Datenlizenz '
'by-2-0; eigene Berechnung/eigene Darstellung')
plt.show()
Download Data
Destatis Data (240 downloads)