In [1]:
import requests, pandas as pd, numpy as np
from requests import session
from bs4 import BeautifulSoup

In [2]:
url='https://www.tomtom.com/en_gb/traffic-index/ranking/'

In [3]:
response = requests.get(url)
soup = BeautifulSoup(response.content)
df=pd.read_html('<table>'+str(soup.findAll('table')[0])+'/<table>')[0]
links=soup.findAll('table')[0].findAll('a')
df['a']=['https://www.tomtom.com'+i['href'] for i in links[::2]]

In [4]:
maxs={}

In [5]:
for url2 in df['a'].values:
    if url2 not in maxs:
        response2 = requests.get(url2)
        soup2 = BeautifulSoup(response2.content)
        divs=soup2.findAll('div', {"class": "PeakCongestion__congestion"})
        peak=soup2.findAll('span', {"class": "TimeWastedInPeaks__hours"})[0].text
        maxs[url2]=[int(i.text[:-1]) for  i in divs]+[peak]
        print(url2)


https://www.tomtom.com/en_gb/traffic-index/bengaluru-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/manila-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bogota-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mumbai-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/pune-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/moscow-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lima-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/new-delhi-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/istanbul-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/jakarta-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bangkok-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kiev-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mexico-city-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bucharest-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/recife-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/saint-petersburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dublin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/odessa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lodz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rio-de-janeiro-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tel-aviv-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/krakow-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/novosibirsk-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sao-paulo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/samara-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/santiago-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/poznan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/salvador-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kharkiv-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/athens-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/los-angeles-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tokyo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/edinburgh-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/chongqing-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/yekaterinburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cairo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/warsaw-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/guangzhou-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/zhuhai-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/vancouver-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wroclaw-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/paris-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rome-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brussels-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/london-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kuala-lumpur-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dnipro-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/budapest-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/shenzhen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/fortaleza-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/beijing-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/new-york-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/luxembourg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sofia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bratislava-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/palermo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/osaka-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rostov-on-don-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/san-francisco-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/belo-horizonte-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/changsha-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/porto-alegre-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brighton-and-hove-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/taipei-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/chengdu-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/buenos-aires-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mons-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/marseille-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bournemouth-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hamburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bydgoszcz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/chelyabinsk-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hull-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/taichung-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cork-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/belfast-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/geneva-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/changchun-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/southampton-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/toronto-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lisbon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/gdansk-gdynia-sopot-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bristol-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/san-jose-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nagoya-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sydney-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kaohsiung-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/manchester-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/reading-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/omsk-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/vilnius-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/naples-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bordeaux-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/berlin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nizhny-novgorod-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/singapore-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/antwerp-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/leicester-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/grenoble-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ankara-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cape-town-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wiesbaden-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/zurich-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/messina-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/auckland-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tomsk-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/milan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hong-kong-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/porto-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/seattle-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tallinn-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/xiamen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/miami-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tainan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/shanghai-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nice-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lugano-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/limerick-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brno-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lyon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/johannesburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/szczecin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/melbourne-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/munich-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cardiff-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nanjing-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/taoyuan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/genoa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nuremberg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/thessaloniki-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/leiden-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/stuttgart-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sapporo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/izmir-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bonn-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/prague-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/catania-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/montreal-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ottawa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/barcelona-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/washington-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/toulon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kazan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/antalya-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/liverpool-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/toulouse-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wellington-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/chicago-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/curitiba-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kassel-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/the-hague-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bari-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/birmingham-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hangzhou-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/vienna-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/honolulu-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/fuzhou-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/stoke-on-trent-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/shenyang-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/strasbourg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sheffield-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/austin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/haarlem-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wuhan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nantes-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nottingham-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/reggio-calabria-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bremen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/stockholm-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/riga-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lausanne-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lublin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/salzburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/frankfurt-am-main-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nijmegen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/turin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/leeds-bradford-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kobe-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/swansea-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/baton-rouge-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/adana-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/san-diego-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/basel-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/boston-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/montpellier-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/shijiazhuang-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kosice-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/portsmouth-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/portland-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/amsterdam-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bialystok-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nashville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/riverside-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/clermont-ferrand-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cologne-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/atlanta-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kiel-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/graz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/arnhem-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ljubljana-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/newcastle-sunderland-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/granada-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/lille-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/glasgow-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bologna-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/sacramento-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/pretoria-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bursa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hamilton-nz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/florence-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dresden-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brisbane-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/halifax-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/coventry-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rotterdam-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kuwait-city-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ningbo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/liege-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dusseldorf-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/palma-de-mallorca-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/philadelphia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rennes-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/riyadh-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/houston-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/adelaide-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tampa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/prato-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/leipzig-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/groningen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/gold-coast-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brest-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/freiburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tianjin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cagliari-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ruhr-region-west-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/gaziantep-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/quanzhou-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/denver-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/innsbruck-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/london-ontario-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/pescara-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hobart-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/madrid-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/santa-cruz-de-tenerife-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/preston-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mersin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/winnipeg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dongguan-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/east-london-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/oslo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/karlsruhe-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/augsburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rouen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/orlando-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/utrecht-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/eindhoven-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/monchengladbach-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/linz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/copenhagen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/charleston-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/aarhus-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/new-orleans-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/quebec-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/boise-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dubai-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/uppsala-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bielsko-biala-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/fresno-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/christchurch-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brasilia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mannheim-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cape-coral-fort-myers-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/munster-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hannover-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/breda-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/le-havre-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ruhr-region-east-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/seville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/pittsburgh-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/las-vegas-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/murcia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/trieste-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bakersfield-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/nancy-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/verona-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/saint-etienne-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bern-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/perth-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/leuven-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tauranga-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tilburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/valencia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/baltimore-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/apeldoorn-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/orleans-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/malaga-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/taranto-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dunedin-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/suzhou-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/livorno-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/newcastle-au-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/providence-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/amersfoort-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ghent-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/middlesbrough-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ostrava-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/charlotte-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dallas-fort-worth-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/jeddah-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/mcallen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wuxi-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hamilton-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/namur-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/durban-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/a-coruna-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tucson-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/turku-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/san-antonio-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/helsinki-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/katowice-urban-area-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/salt-lake-city-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/gothenburg-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/oxnard-thousand-oaks-ventura-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/avignon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/reykjavik-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/greenville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/raleigh-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/phoenix-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/konya-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/odense-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/las-palmas-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/alicante-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bielefeld-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/braga-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/birmingham-alabama-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/zwolle-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/le-mans-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/calgary-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/reggio-emilia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dijon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/colorado-springs-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wuppertal-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/jacksonville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/albuquerque-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/padua-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/parma-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/santander-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/den-bosch-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/hartford-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/canberra-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/funchal-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/minneapolis-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kayseri-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/ravenna-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bruges-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/columbus-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cincinnati-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/reims-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/edmonton-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/new-haven-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/detroit-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/virginia-beach-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/el-paso-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kitchener-waterloo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tours-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/grand-rapids-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/albany-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/gijon-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/pamplona-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/louisville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kortrijk-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bergen-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/allentown-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/vigo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/coimbra-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tampere-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/worcester-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/trondheim-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/malmo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/buffalo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/memphis-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/modena-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/st-louis-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/indianapolis-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cordoba-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/brescia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/vitoria-gasteiz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/omaha-council-bluffs-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/oklahoma-city-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cartagena-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/zaragoza-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/rochester-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/san-sebastian-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/wollongong-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/charleroi-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/valladolid-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/stavanger-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/oviedo-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/columbia-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/milwaukee-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bilbao-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/bloemfontein-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/tulsa-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cleveland-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/knoxville-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/kansas-city-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/richmond-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/winston-salem-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/little-rock-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/abu-dhabi-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/almere-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/dayton-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/syracuse-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/akron-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/cadiz-traffic#statistics
https://www.tomtom.com/en_gb/traffic-index/greensboro-high-point-traffic#statistics

In [6]:
maxdf=pd.DataFrame(maxs).T
maxdf.columns=['morning','eve','waste']

In [7]:
dc=df.set_index('a').join(maxdf).drop(['Unnamed: 5','World Rank'],axis=1).reset_index()

In [8]:
dc['Congestion Level2']=dc['Congestion Level'].str.split('%').str[0]
dc['waste2']=dc['waste'].str.split(' ').str[0]

In [44]:
dc.to_excel('dc.xlsx')

In [45]:
dc.to_csv('dc.csv')

In [46]:
!pip install pygeocoder


Collecting pygeocoder
  Using cached https://files.pythonhosted.org/packages/3b/79/2cf3a4dfe54705bbf07cbb25940078dfa595608aa4ecb9f0aaaae9faba08/pygeocoder-1.2.5.tar.gz
Requirement already satisfied: requests>=1.0 in c:\programdata\anaconda3\lib\site-packages (from pygeocoder) (2.22.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests>=1.0->pygeocoder) (1.25.7)
Requirement already satisfied: idna<2.9,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests>=1.0->pygeocoder) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests>=1.0->pygeocoder) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests>=1.0->pygeocoder) (2019.11.28)
Building wheels for collected packages: pygeocoder
  Building wheel for pygeocoder (setup.py): started
  Building wheel for pygeocoder (setup.py): finished with status 'done'
  Created wheel for pygeocoder: filename=pygeocoder-1.2.5-cp37-none-any.whl size=8889 sha256=8c38ef797678f2bc66f9b124dcd0678a9993de7c7ab5fbe420d105c945237b92
  Stored in directory: C:\Users\csala\AppData\Local\pip\Cache\wheels\7c\4c\00\d05c66c4af5411c554c91b8079732c8a0359c2226fb8c01031
Successfully built pygeocoder
Installing collected packages: pygeocoder
Successfully installed pygeocoder-1.2.5

In [47]:
from pygeocoder import Geocoder
apikey='AIzaSyB7joM_loHFb1SYFJevWfMmBCD9VO2uykc'

In [80]:
try:
    geos=pd.read_csv('dcg.csv')
    geos.index=geos['City']+', '+geos['Country']
    geos=geos[['lat','lon']].T.to_dict()
    geos={i:tuple(geos[i].values()) for i in geos}
except:
    geos={}

In [81]:
for i in dc.index[:]:
    to_geo=dc.loc[i]['City']+', '+dc.loc[i]['Country']
    if to_geo not in geos:
        print(to_geo)
        coords=Geocoder(apikey).geocode(to_geo).coordinates
        geos[to_geo]=coords

In [84]:
dc['lat']=[i[0] for i in geos.values()]
dc['lon']=[i[1] for i in geos.values()]

In [85]:
dc.to_csv('dcg.csv')

Load from here


In [9]:
dc=pd.read_csv('dcg.csv')

https://population.un.org/wup/Download/ -> Urban Agglomerations


In [10]:
pop2=pd.read_csv('worldcities.csv')

In [11]:
pop2


Out[11]:
city city_ascii lat lng country iso2 iso3 admin_name capital population id
0 Tokyo Tokyo 35.6850 139.7514 Japan JP JPN Tōkyō primary 35676000.0 1392685764
1 New York New York 40.6943 -73.9249 United States US USA New York NaN 19354922.0 1840034016
2 Mexico City Mexico City 19.4424 -99.1310 Mexico MX MEX Ciudad de México primary 19028000.0 1484247881
3 Mumbai Mumbai 19.0170 72.8570 India IN IND Mahārāshtra admin 18978000.0 1356226629
4 São Paulo Sao Paulo -23.5587 -46.6250 Brazil BR BRA São Paulo admin 18845000.0 1076532519
... ... ... ... ... ... ... ... ... ... ... ...
15488 Timmiarmiut Timmiarmiut 62.5333 -42.2167 Greenland GL GRL Kujalleq NaN 10.0 1304206491
15489 Cheremoshna Cheremoshna 51.3894 30.0989 Ukraine UA UKR Kyyivs’ka Oblast’ NaN 0.0 1804043438
15490 Ambarchik Ambarchik 69.6510 162.3336 Russia RU RUS Sakha (Yakutiya) NaN 0.0 1643739159
15491 Nordvik Nordvik 74.0165 111.5100 Russia RU RUS Krasnoyarskiy Kray NaN 0.0 1643587468
15492 Ennadai Ennadai 61.1333 -100.8833 Canada CA CAN Nunavut NaN 0.0 1124019423

15493 rows × 11 columns


In [12]:
def ccc(c,country):
    if c=='Moscow region (oblast)': return 'Moscow'
    if c=='Rostov-on-Don': return 'Rostov-na-Donu'
    if c=='Gdansk, Gdynia and Sopot': return 'Gdansk+Gdynia'
    if c=='Nizhny Novgorod': return 'Nizhniy Novgorod'
    if c=="Kazan": return "Kazan'"
    if c=="Birmingham-Wolverhampton": return "Birmingham+Wolverhampton"
    if c=='Frankfurt am Main': return 'Frankfurt'
    if c=='Reggio Calabria': return 'Reggio di Calabria'
    if c=='Leeds-Bradford': return 'Leeds+Bradford'
    if c=='Newcastle-Sunderland': return 'Newcastle+Sunderland'
    if c=='Freiburg': return 'Freiburg im Breisgau'
    if c=='Ruhr region west': return 'Duisburg+Dusseldorf+Bonn+Cologne'
    if c=='Ruhr region east': return 'Essen+Dortmund+Wuppertal'
    if c=='Cape Coral-Fort Myers': return 'Cape Coral+Fort Myers'
    if c=='Oxnard-Thousand Oaks-Ventura': return 'Oxnard+Thousand Oaks'
    if c=='Dallas-Fort Worth': return 'Dallas+Fort Worth'
    if c=='Katowice urban area': return 'Katowice'
    if c=='Gothenburg': return 'Goteborg'
    if c=='Odessa': return 'Odesa'
    if c=='Kitchener-Waterloo': return 'Kitchener'
    if c=='Omaha-Council Bluffs': return 'Omaha+Council Bluffs'
    if c=='Greensboro-High Point': return 'Greensboro+High Point'
    if c=='Den Bosch': return "'s-Hertogenbosch"
    if c=='Hull': return 'Kingston upon Hull'
    if c=='Swansea': return 'Abertawe'
    if c=='Newcastle': 
        if country=='United Kingdom': return 'Newcastle upon Tyne'
        return 'Newcastle'
    if c=='Seville': return 'Sevilla'
    if c=='Ghent': return 'Gent'
    return c

In [13]:
def cnc(c):
    if c=='United States of America': return 'United States'
    return c

In [14]:
pops={}
missing=[]
for i in dc.index:
    city=dc.loc[i]['City']
    country0=dc.loc[i]['Country']
    country=cnc(country0)
    if country not in pop2['country'].unique():
        print(country)
    pop2a=pop2[pop2['country']==country]
    index=city+', '+country0
    for c in ccc(city,country).split('+'):
        c=ccc(c,country)
        if c in ['San Sebastian']:
            print(city,c)
            missing.append(city+', '+country)
        elif c in pop2a['city'].values:
            if index not in pops:pops[index]=0
            pops[index]+=pop2a.drop_duplicates('city').set_index('city').loc[c]['population']
        elif c in pop2['city_ascii'].values:
            if index not in pops:pops[index]=0
            pops[index]+=pop2a.drop_duplicates('city_ascii').set_index('city_ascii').loc[c]['population']
        elif c in pop2['admin_name'].values:
            if index not in pops:pops[index]=0
            pops[index]+=pop2a.drop_duplicates('admin_name').set_index('admin_name').loc[c]['population']
        else:
            print(city,c,index)
            missing.append(index)


Leiden Leiden Leiden, Netherlands
Nijmegen Nijmegen Nijmegen, Netherlands
Palma de Mallorca Palma de Mallorca Palma de Mallorca, Spain
Prato Prato Prato, Italy
Monchengladbach Monchengladbach Monchengladbach, Germany
Bielsko-Biala Bielsko-Biala Bielsko-Biala, Poland
Breda Breda Breda, Netherlands
Leuven Leuven Leuven, Belgium
Tilburg Tilburg Tilburg, Netherlands
Apeldoorn Apeldoorn Apeldoorn, Netherlands
Amersfoort Amersfoort Amersfoort, Netherlands
Avignon Avignon Avignon, France
Las Palmas Las Palmas Las Palmas, Spain
Reggio Emilia Reggio Emilia Reggio Emilia, Italy
Padua Padua Padua, Italy
Kortrijk Kortrijk Kortrijk, Belgium
Brescia Brescia Brescia, Italy
San Sebastian San Sebastian
Almere Almere Almere, Netherlands

In [15]:
fixed={}

In [16]:
for c in missing:
    i=c.split(',')
    url3='http://population.city/'+i[1].lower().strip()+'/'+i[0].lower().strip()+'/'
    #print(url3)
    response = requests.get(url3)
    soup = BeautifulSoup(response.content)
    em=soup.findAll('em')
    if em:
        fixed[c]=float(em[0].text[:-1].replace(' ',''))
        print('OK',c)
    else:
        print('ERROR',c)


OK Leiden, Netherlands
OK Nijmegen, Netherlands
ERROR Palma de Mallorca, Spain
OK Prato, Italy
OK Monchengladbach, Germany
OK Bielsko-Biala, Poland
OK Breda, Netherlands
OK Leuven, Belgium
OK Tilburg, Netherlands
OK Apeldoorn, Netherlands
OK Amersfoort, Netherlands
OK Avignon, France
ERROR Las Palmas, Spain
ERROR Reggio Emilia, Italy
ERROR Padua, Italy
OK Kortrijk, Belgium
OK Brescia, Italy
ERROR San Sebastian, Spain
ERROR Almere, Netherlands

In [17]:
pops.update(fixed)

In [18]:
#manual from Wiki
pops.update({
'Palma de Mallorca, Spain':393256.0,
'Las Palmas, Spain':384315.0,
'Reggio Emilia, Italy':172326.0,
'Padua, Italy':214000.0,
'Almere, Netherlands':207904.0,
'San Sebastian, Spain':186095.0    
})

In [19]:
#manual from Wiki for unflagged
pops.update({
'Preston, United Kingdom':141251.0,
'Birmingham-Wolverhampton, United Kingdom': 1157579.0+259376.0,
'Mersin, Turkey':1038940.0    
})

Manual overwrites


In [20]:
pops['New Delhi, India']=20268785.0

In [21]:
dp=pd.DataFrame(pops,index=['pop']).T

In [22]:
dc['cc']=dc['City']+', '+dc['Country']

In [23]:
dcp=dc.set_index('cc').join(dp).reset_index()
len(dcp)


Out[23]:
416

In [24]:
dcp[np.isnan(dcp['pop'])]


Out[24]:
cc Unnamed: 0 a Rank by filter City Country Congestion Level morning eve waste Congestion Level2 waste2 lat lon pop

In [25]:
len(dcp)


Out[25]:
416

In [26]:
#drop manual duplicates
dcp=dcp[~(dcp['City'].isin(['Duisburg','Dusseldorf','Bonn','Cologne']))]
len(dcp)


Out[26]:
413

In [27]:
dcr=dcp[dcp['Country'].isin(['Austria','Belgium','Bulgaria','Croatia','Cyprus','Czechia','Denmark',
                        'Estonia','Finland','France','Germany','Greece','Hungary','Ireland','Italy',
                        'Latvia','Lithuania','Luxembourg','Malta','Netherlands','Poland',
                        'Portugal','Romania','Slovakia','Slovenia','Spain','Sweden'])]\
                .sort_values('Rank by filter').reset_index()
dcr['eu']=dcr.index+1
dcw=dcp.join(dcr.set_index('City')[['eu']],on='City').fillna(0)

In [28]:
dcx=dcw.set_index('cc').T.to_dict()

In [29]:
dcx['Washington, United States of America']['lat']=38.930378
dcx['Washington, United States of America']['lon']=-77.057839
dcx['Ruhr region west, Germany']['lat']=51.347795
dcx['Ruhr region west, Germany']['lon']=6.699458
dcx['Ruhr region east, Germany']['lat']=51.484191
dcx['Ruhr region east, Germany']['lon']=7.457383
dcx['Quebec, Canada']['lat']=46.799437
dcx['Quebec, Canada']['lon']=-71.264797

In [30]:
pd.DataFrame(dcx).T.to_csv('dcx.csv')