In [1]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
In [2]:
%matplotlib widget
Načtení tabulky z webu¶
In [3]:
df = pd.read_html('https://cs.wikipedia.org/wiki/Brno',
match='Vývoj počtu obyvatel žijících na území současného města Brna')
df = df[0].T
df = df.reset_index()
df.columns = ['year', 'number']
df.year = pd.to_numeric(df.year)
df.number = df.number.apply(lambda x: int(x.replace(' ', '')))
df.head()
Out[3]:
In [4]:
fig, ax = plt.subplots(tight_layout=True)
ax.plot(df.year, df.number, 'b-o')
ax.set_xlabel('rok')
ax.set_ylabel('počet obyvatel')
ax.set_title('Brno - počet obyvatel');
In [5]:
fig, ax = plt.subplots(tight_layout=True)
ax.plot(df.year.loc[1:], np.diff(df.number), 'b-o')
ax.set_xlabel('rok')
ax.set_ylabel('počet obyvatel')
ax.set_title('Brno - přírůstek obyvatel mezi jednotlivými obdobími');