data_from_web

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]:
year number
0 1869 104977
1 1880 120122
2 1890 145782
3 1900 176645
4 1910 216709
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');
Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …
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');
Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …