Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import urllib
  5. from bs4 import BeautifulSoup
  6. url_adresa = 'https://en.wikipedia.org/wiki/Demographics_of_Croatia'
  7. html = urllib.urlopen(url_adresa).read()
  8. soup = BeautifulSoup(html)
  9. table = soup.find("table")
  10. ethic_groups=[];
  11. census48 = [];
  12. census53 = [];
  13. census61 = [];
  14. census71 = [];
  15. census81 = [];
  16. census91 = [];
  17. census01 = [];
  18. census11 = [];
  19. for table_row in soup.select("tr"):
  20.     cells = table_row.findAll("td")
  21.     if len(cells)==17:
  22.         ethic_groups.append(cells[0].text.strip())
  23.         c48 =cells[2].text.strip()
  24.         if c48 == '':
  25.             c48=0
  26.         census48.append(float(c48));
  27.         c53 =cells[4].text.strip()
  28.         if c53 == '':
  29.             c53=0
  30.         census53.append(float(c53));
  31.         census61.append(float(cells[6].text.strip()))
  32.         census71.append(float(cells[8].text.strip()))
  33.         census81.append(float(cells[10].text.strip()))
  34.         census91.append(float(cells[12].text.strip()))
  35.         census01.append(float(cells[14].text.strip()))
  36.         census11.append(float(cells[16].text.strip()))  
  37. d = {'1948.':census48,'1953.': census53,'1961.': census61,'1971.': census71,'1981.':census81,'1991.':census91,'2001.':census01,'2011.':census11}
  38. df = pd.DataFrame(d,index=ethic_groups)
  39. ax = df.plot.bar()
  40. ax.set_ylabel('Postotak stanovnistva')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement