3rd Unit

You might also like

Download as pdf
Download as pdf
You are on page 1of 12
In [180): dataz=pd.read_csv("0:\bM Lab\Wall_custoners.csv" index col="Custonerb") tn (181): data out 2 ender Age Annual ncome 8} Spending Score (1-100) costomard 2 Wale 21 6 1 5 Fenale 3 ” ” 197 Female 45 8 a 190 wale 32 8 ™ 1m (182) ead_esv("D:\0M Lab\Wal_Custorers. csv" jnanes ayes aye) in (183): dataz out (83 a be ‘ . (© Cusine) Gander Age Arr ome i) Spenang Ser (-100| 4 1 Maw 9 5 » 4 4 Female 23 6 ” 7197 ona 45 28 » m0 20 Mas 20 wr ® 201 rows * §eokimns In [188]; datazepd.cead_c5¥("D:\DM Lab\Mall_custorers.csv" nanese['a","b',"€", "4" "e"Jeindex_cole[ a", 'b"J,headersNone) -head(10 1m (190): dataz out 398) ‘customer ‘Age Armuancone i) Spend Sere (1-100) 1 6 4 xo ‘ a 6 ” 7 28 6 In [293]: dataz=pd.read_csv("0:\b" Lab\Mal1_custorers.csv",nanes=['2","b','c','é",e"J+skiprows=[@,1])-head(10) 1m (294): data outa In [295]: |datazepd.read_esv("0:\b" Lab\Mall_custorers.c5¥" nrowse5) aataz out 395) Custer Gander Age Annuatincome (x) Spending Sore (1-100) In [202]: new_esvepd.read_esv("C:/Users/Sanjay Downloads /newfile. csv") 1m (203): |new_esv out 203; 1m (233 in [219]: html_dataspd.eead_table( https://umw3schools.coa/html/html_tables. 5p") tn (220): ntmi_data out (228) me , m0 tay 7822 ows * 1 columns tn (221) 1n (222 out 222) 1m (224) in [225] mn (227 in (228 In (230 tn (231) out (281) datarpd.bataFrane({ ane": (A, "B,C" 'D' Dy wage” :[20,21,22, 23] » aaa Nome Age + oe a data. to_esv("D:/F0s/toFiles/aata.esv") data. to_excel("0:/+05/tofiles/data.x15x°) ata. to_Json(":/F05/toftes/data. json") Working with Delimited Formats mort Js0n vith open("C:/Users/Sanjay/Dounloads/MOCK_OATA (3).Js0n", ‘r") as Json_file: eaced_éata = json-load(}son_File) petnt(laaded data) Pretrieving the data ‘Coname": ‘Zohn’, age": 38, “elty': “New Yon) inserting the data mort json data = {°nane": “John', ‘age’ 38, ‘ely’: "New York’ vith open("C:/Users/Sanjay/Dounloads/MOCK_DATA (3).Js0n", 'w") as json_file: son. dump(data, Json_file) mort xnl.ctree.€lenentTree as ET f Porse the wm file tree = ET. parse(“C:/Users/Sanjay/Downloads/newFse.x") 1 Assume the 20. structure has only one person person = root. find( “person” # extract dota fron the person rane = person. find( ‘rane ) text “aoha" tn (232) in (233 In (235) creating an xml Import xal.ctree.ElenentTree as ET Poot = ET-Elewent("aeople") # create a person element person = E1,Sudelenent(root, “person’) # aa dota to the person eLenent ane = ET. Subélenent (person, "none" hane.text'= "ohn age = ET-Subelenent(pesson, ‘age') age. text 30 city = ET.Subelenent (person, ‘city") city. text = "New ¥ork 1 Create an ElenentTree object ‘tree = ET.Elenent"ree(root) rice to the xm file tereewurdte( ‘output. xni") mort csv data = [['Nane', ‘Age’, ‘city'], [rJohn", 38, “lew York}, [ratiee', 25, “Landon'}} # wricing to a csv Fite ith open('data.csv', 'w', newlines'') as sv writer = esviaiten(f) ceviwrdzer.wraterows (data) # Reading from a CSV file ith open('data.csy'y 'r') as F ‘esv_reager = csv. readee(#) loaded_ésta = List(cs¥_reader) Webscrapping mort requests Fron bs lmport GeautifulSoup quests. get("httos://ior-google.coa") soup-Beautifulsoup(r.content, ‘htni.parser") In [236): point (soup. pretesfy()) <1DocTYPE eet» cheae> eneta contenta"text neal; charsetautf-8% hetp-equive"Content-Type"/> ‘neta cortent="/images/branding/googles/1x/googleg, standard_color_228dp.pag” itenprop-"inage"/> Google -3, taghare)(a="t @);3).call(this); ‘ "ear, tguse (font sie:1xpating top: nporcans agar (helah: pe tgvser (oan otton:7x Lngortnete Gex}omedis 511{ go1{height:2zpxjnangin-right: .Senjvereical-2lign:t a. gb1,2.goa(te nderline linportant}acgbt.a.gbe{coler:#9@e linportont} gbi sgbi(colors#éd8e27 Tinportant} gb? seb4{colors#900 liapor tant) body, td,2,9, .n(font-fonily:arial, sans-serif )body(nargin:0;overFlow-y:scrol1)#gog( padding: 3px Box © te.sen}-gacie td{line-helght:17px) forn{nargin-bot tor: 28px} (color :#196742}en{ Fort -welght:bold; font~styie:normal}.1s ‘height: 25pxswiden:498px) gs, st (font 85x arial, sans-seri¢) .gsfs(“ont:'Jpx sraal,sans-sers#).05(display:inline- boxsdisplaysinline-bloeksnargin. 3px dpxsnargin-leFt 4px} inpus font-family: inherst}body( background: FFs {script ronce="Mipdwé NEC A8F-g"> (Funetion() (window. google -erde{5srs4 bv: 1917, de: var hethis| |self;var ky 1enul!=(kshemed) 24:1, 95 , (aib,dyn,0) eovoid Oenne?2:€;bAK(roatta.nessage) ;void Gmm-chA(da(});d-cade"ple_"rgoogle.ple+”.aple“+google.aplesif (Google-dl return google.dl(s,¢, 4) null; 1#(@>v){uindow.consolessconsole-enror(3,4);1#(-2-=ev) threw ajbelt}eise belal [Ta.nessage||"Error loacing script*-nra.nessage] |q>=188in?11:1@;i¢(Ib)return null sqs+dzd] | ():bvencodeURIConponent ar cu"/gen.2042atypnidel="*0 (google. KET) ;google.KEXPTEN(c+="@ jexpid="+b(google-KEXPT)) c=" Astcpg="=d(google.s9)="8) Srevso(t-Jan)+"Bbver="+ 5(¢.be);uar faa. 1inelumber;votd @l==F48(cr="alsne="+#);var gaa. fileNane BRB (Ocg. indexOF(*-extenston:/*)86(e=5) c+="8 script="4n(g), faag-=window. location. hrefa(f-cocunent .cocunentElenent outernMl.split("\n)[],ct="deade"¥0(9F sub tring(0, 300):"No script found. ”))) google ple¥sl=--google plesBle-2) c+="Ajsel="resfor(var Un a)cr="#,e+=0(U) e+ sTessb(6[u]);e-ce"densge"eb(a-nanes”! "oa.messaga) je-ce™Ajest="40(2,. yheae> chady becolor="#ee>