Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- import urllib
- from bs4 import BeautifulSoup
- url_adresa = 'https://en.wikipedia.org/wiki/Demographics_of_Croatia'
- html = urllib.urlopen(url_adresa).read()
- soup = BeautifulSoup(html)
- table = soup.find("table")
- ethic_groups=[];
- census48 = [];
- census53 = [];
- census61 = [];
- census71 = [];
- census81 = [];
- census91 = [];
- census01 = [];
- census11 = [];
- for table_row in soup.select("tr"):
- cells = table_row.findAll("td")
- if len(cells)==17:
- ethic_groups.append(cells[0].text.strip())
- c48 =cells[2].text.strip()
- if c48 == '':
- c48=0
- census48.append(float(c48));
- c53 =cells[4].text.strip()
- if c53 == '':
- c53=0
- census53.append(float(c53));
- census61.append(float(cells[6].text.strip()))
- census71.append(float(cells[8].text.strip()))
- census81.append(float(cells[10].text.strip()))
- census91.append(float(cells[12].text.strip()))
- census01.append(float(cells[14].text.strip()))
- census11.append(float(cells[16].text.strip()))
- d = {'1948.':census48,'1953.': census53,'1961.': census61,'1971.': census71,'1981.':census81,'1991.':census91,'2001.':census01,'2011.':census11}
- df = pd.DataFrame(d,index=ethic_groups)
- ax = df.plot.bar()
- ax.set_ylabel('Postotak stanovnistva')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement