Course Hero Logo

Lab TWO ZWEI- Part ZWEI.docx - Lab 2: Data Wrangling and...

This preview shows page 1 - 4 out of 173 pages.

Lab 2: Data Wrangling and Web scrapingPart 2Varunraj KholePython script:# -*- coding: utf-8 -*-"""Created on Thu Mar 30 16:01:43 2021@author: VKhole"""#Web Scraping using beautiful Soupimport pandas as pdfrombs4 import BeautifulSoupimport requestsres = requests.get("-info/stats/Media/Households-with-television")resres.contentsoup = BeautifulSoup(res.content, 'lxml')print(soup.prettify())
table = soup.find_all('table')[0]df = pd.read_html(str(table))[0]df1= df[["COUNTRY","AMOUNT","DATE"]]df1.head()Output:"""Created on Thu Mar 30 16:01:43 2021@author: VKhole"""#Web Scraping using beautiful Soupimport pandas as pdfrombs4 import BeautifulSoupimport requestsres = requests.get("-television")resres.contentOut[3]: b'\n<!DOCTYPE HTML>\n<html>\n<head>\n<meta charset="utf-8">\n<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n\n\n<script
type="text/javascript">;window._taboola=window._taboola||[];_taboola.push({category:\'auto\'});!function(e,f,u,i){if(!document.getElementById(i)){e.async=1;e.src=u;e.id=i;f.parentNode.insertBefore(e,f);}}(document.createElement(\'script\'),document.getElementsByTagName(\'script\')[0],\'//cdn.taboola.com/libtrc/nationmaster/loader.js\',\'tb_loader_script\');if(window.performance&&typeof window.performance.mark==\'function\'){window.performance.mark(\'tbl_ic\');}</script>\n\n<title>Countries Compared by Media&gt; Households with television. International Statistics at NationMaster.com</title>\n<meta name="description" content="" />\n<meta name="author" content="">\n<metaname="viewport" content="width=device-width,initial-scale=1, user-scalable=no">\n\n<meta property="og:type" content="website">\n<meta property="og:url"content="">\n\n<meta property="og:title" content="Countries Compared by Media &gt; Households withtelevision. International Statistics at NationMaster.com">\n\n\n<metaproperty="og:description" content="Households with television are the share of households witha television set. Some countries report only the number of households with a color television set,and therefore the true number may be higher than reported.">\n\n\n\n<metaproperty="og:image" content="-stats.png">\n\n<link rel="stylesheet"href="" type="text/css" />\n<script src=""></script>\n<script type="text/javascript">;var _gaq=_gaq||[];_gaq.push([\'_setAccount\',\'UA-317061-1\']);$(function(){_gaq.push([\'_trackPageview\']);});(function(){varga=document.createElement(\'script\');ga.type=\'text/javascript\';ga.async=true;ga.src=(\'https:\'==document.location.protocol?\'https://\':\'http://\')+\'stats.g.doubleclick.net/dc.js\';vars=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(ga,s);})();varPATHS={\'watermark\':""};varVARS={\'signup_url\':"/account/signup/",\'track_url\':"/track",\'page_survey_url\':"/page-survey",\'vote_up_url\':"/so/vote-up",\'vote_down_url\':"/so/vote-down",\'sidebar_ajax_url\':"/sidebar",\'sidebar_country_profile_url\':"/country-info/profiles/obj-

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 173 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
header class

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture