Talk given at RMACC August 17, 2017 titled "Practical Data Wrangling in Pandas".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2_importing_data.ipynb 192 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "** NAVIGATION **\n",
  8. "\n",
  9. "**Got Pandas? _Practical Data Wrangling with Pandas_**\n",
  10. "\n",
  11. "* [Introduction](./0_introduction.ipynb)\n",
  12. "1. [Data Structures](./1_data_structures.ipynb)\n",
  13. "2. **Importing Data**\n",
  14. "3. [Manipulating DataFrames](./3_dataframe_operations.ipynb)\n",
  15. "4. [Wrap Up](4_wrapping_up.ipynb)\n",
  16. "\n",
  17. "---"
  18. ]
  19. },
  20. {
  21. "cell_type": "markdown",
  22. "metadata": {
  23. "toc": "true"
  24. },
  25. "source": [
  26. "# Table of Contents\n",
  27. " <p><div class=\"lev1 toc-item\"><a href=\"#Importing-Data-in-Pandas\" data-toc-modified-id=\"Importing-Data-in-Pandas-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Importing Data in Pandas</a></div><div class=\"lev2 toc-item\"><a href=\"#Importing-Pandas\" data-toc-modified-id=\"Importing-Pandas-11\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Importing Pandas</a></div><div class=\"lev2 toc-item\"><a href=\"#Loading-CSV-and-Excel\" data-toc-modified-id=\"Loading-CSV-and-Excel-12\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Loading CSV and Excel</a></div><div class=\"lev3 toc-item\"><a href=\"#CSV\" data-toc-modified-id=\"CSV-121\"><span class=\"toc-item-num\">1.2.1&nbsp;&nbsp;</span>CSV</a></div><div class=\"lev3 toc-item\"><a href=\"#Accessing-column-data-by-label\" data-toc-modified-id=\"Accessing-column-data-by-label-122\"><span class=\"toc-item-num\">1.2.2&nbsp;&nbsp;</span>Accessing column data by label</a></div><div class=\"lev2 toc-item\"><a href=\"#Excel\" data-toc-modified-id=\"Excel-13\"><span class=\"toc-item-num\">1.3&nbsp;&nbsp;</span>Excel</a></div><div class=\"lev2 toc-item\"><a href=\"#JSON\" data-toc-modified-id=\"JSON-14\"><span class=\"toc-item-num\">1.4&nbsp;&nbsp;</span>JSON</a></div><div class=\"lev2 toc-item\"><a href=\"#SQL\" data-toc-modified-id=\"SQL-15\"><span class=\"toc-item-num\">1.5&nbsp;&nbsp;</span>SQL</a></div>"
  28. ]
  29. },
  30. {
  31. "cell_type": "markdown",
  32. "metadata": {},
  33. "source": [
  34. "---"
  35. ]
  36. },
  37. {
  38. "cell_type": "markdown",
  39. "metadata": {},
  40. "source": [
  41. "# Importing Data in Pandas\n",
  42. "\n",
  43. "Pandas supports a number of data formats out of the box including:\n",
  44. "\n",
  45. "* CSV, Excel\n",
  46. "* JSON\n",
  47. "* HDF5\n",
  48. "* SQL databases\n",
  49. "* and others\n",
  50. "\n",
  51. "The major benefit for using Pandas to load these data is that it provides a simple, consistent mechanism for each of them and loads them directly into the Pandas DataFrame in a single operation, reducing the need to go elsewhere to perform the same operations with more code or overhead.\n",
  52. "\n",
  53. "Pandas I/O supports loading these data formats directly from local storage or using a URL containing such data. The convenience being that the resource string used can be either a local/network file string or a URL.\n",
  54. "\n",
  55. "**NOTEBOOK OBJECTIVES**\n",
  56. "\n",
  57. "In this notebook we'll:\n",
  58. "\n",
  59. "* load a local and remote csv file, \n",
  60. "* load Excel datafile,\n",
  61. "* load JSON data,\n",
  62. "* load data via SQL queries."
  63. ]
  64. },
  65. {
  66. "cell_type": "markdown",
  67. "metadata": {},
  68. "source": [
  69. "## Importing Pandas\n",
  70. "\n",
  71. "You will most often load the Pandas library with the following line:"
  72. ]
  73. },
  74. {
  75. "cell_type": "code",
  76. "execution_count": 1,
  77. "metadata": {
  78. "collapsed": true
  79. },
  80. "outputs": [],
  81. "source": [
  82. "import pandas as pd"
  83. ]
  84. },
  85. {
  86. "cell_type": "markdown",
  87. "metadata": {},
  88. "source": [
  89. "## Loading CSV and Excel\n",
  90. "\n",
  91. "### CSV\n",
  92. "\n",
  93. "CSV files are still a staple in data file formats. They're portable, flexible, flat, usually easy to parse and ubiquitous. We will begin by showing how to use Pandas to load CSV directly into a DataFrame.\n",
  94. "\n",
  95. "**DATA SOURCE**\n",
  96. "\n",
  97. "US Baseball Statistics Archive by Sean Lahman (CCBY-SA 3.0):\n",
  98. "\n",
  99. "* [http://seanlahman.com/baseball-archive/statistics/](http://seanlahman.com/baseball-archive/statistics/)\n",
  100. "* [https://github.com/chadwickbureau/baseballdatabank](https://github.com/chadwickbureau/baseballdatabank)\n",
  101. "\n",
  102. "We have put the dataset for [batting data](./datasets/Batting.csv) into our local `datasets` folder.\n",
  103. "\n",
  104. "Loading this into a Pandas DataFrame will require us to use the [`read_csv`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html#pandas.read_csv) function, which will attempt to load the CSV data directly into the DataFrame."
  105. ]
  106. },
  107. {
  108. "cell_type": "code",
  109. "execution_count": 2,
  110. "metadata": {
  111. "collapsed": true
  112. },
  113. "outputs": [],
  114. "source": [
  115. "df = pd.read_csv(\"./datasets/Batting.csv\")"
  116. ]
  117. },
  118. {
  119. "cell_type": "markdown",
  120. "metadata": {},
  121. "source": [
  122. "If we inspect this DataFrame, will get exactly what we expect -- each line corresponding to the row in file. __NOTE__: where there are missing values, Pandas will automatically fill the data with `NaN`."
  123. ]
  124. },
  125. {
  126. "cell_type": "code",
  127. "execution_count": 3,
  128. "metadata": {},
  129. "outputs": [
  130. {
  131. "data": {
  132. "text/html": [
  133. "<div>\n",
  134. "<style>\n",
  135. " .dataframe thead tr:only-child th {\n",
  136. " text-align: right;\n",
  137. " }\n",
  138. "\n",
  139. " .dataframe thead th {\n",
  140. " text-align: left;\n",
  141. " }\n",
  142. "\n",
  143. " .dataframe tbody tr th {\n",
  144. " vertical-align: top;\n",
  145. " }\n",
  146. "</style>\n",
  147. "<table border=\"1\" class=\"dataframe\">\n",
  148. " <thead>\n",
  149. " <tr style=\"text-align: right;\">\n",
  150. " <th></th>\n",
  151. " <th>playerID</th>\n",
  152. " <th>yearID</th>\n",
  153. " <th>stint</th>\n",
  154. " <th>teamID</th>\n",
  155. " <th>lgID</th>\n",
  156. " <th>G</th>\n",
  157. " <th>AB</th>\n",
  158. " <th>R</th>\n",
  159. " <th>H</th>\n",
  160. " <th>2B</th>\n",
  161. " <th>...</th>\n",
  162. " <th>RBI</th>\n",
  163. " <th>SB</th>\n",
  164. " <th>CS</th>\n",
  165. " <th>BB</th>\n",
  166. " <th>SO</th>\n",
  167. " <th>IBB</th>\n",
  168. " <th>HBP</th>\n",
  169. " <th>SH</th>\n",
  170. " <th>SF</th>\n",
  171. " <th>GIDP</th>\n",
  172. " </tr>\n",
  173. " </thead>\n",
  174. " <tbody>\n",
  175. " <tr>\n",
  176. " <th>0</th>\n",
  177. " <td>abercda01</td>\n",
  178. " <td>1871</td>\n",
  179. " <td>1</td>\n",
  180. " <td>TRO</td>\n",
  181. " <td>NaN</td>\n",
  182. " <td>1</td>\n",
  183. " <td>4</td>\n",
  184. " <td>0</td>\n",
  185. " <td>0</td>\n",
  186. " <td>0</td>\n",
  187. " <td>...</td>\n",
  188. " <td>0.0</td>\n",
  189. " <td>0.0</td>\n",
  190. " <td>0.0</td>\n",
  191. " <td>0</td>\n",
  192. " <td>0.0</td>\n",
  193. " <td>NaN</td>\n",
  194. " <td>NaN</td>\n",
  195. " <td>NaN</td>\n",
  196. " <td>NaN</td>\n",
  197. " <td>NaN</td>\n",
  198. " </tr>\n",
  199. " <tr>\n",
  200. " <th>1</th>\n",
  201. " <td>addybo01</td>\n",
  202. " <td>1871</td>\n",
  203. " <td>1</td>\n",
  204. " <td>RC1</td>\n",
  205. " <td>NaN</td>\n",
  206. " <td>25</td>\n",
  207. " <td>118</td>\n",
  208. " <td>30</td>\n",
  209. " <td>32</td>\n",
  210. " <td>6</td>\n",
  211. " <td>...</td>\n",
  212. " <td>13.0</td>\n",
  213. " <td>8.0</td>\n",
  214. " <td>1.0</td>\n",
  215. " <td>4</td>\n",
  216. " <td>0.0</td>\n",
  217. " <td>NaN</td>\n",
  218. " <td>NaN</td>\n",
  219. " <td>NaN</td>\n",
  220. " <td>NaN</td>\n",
  221. " <td>NaN</td>\n",
  222. " </tr>\n",
  223. " <tr>\n",
  224. " <th>2</th>\n",
  225. " <td>allisar01</td>\n",
  226. " <td>1871</td>\n",
  227. " <td>1</td>\n",
  228. " <td>CL1</td>\n",
  229. " <td>NaN</td>\n",
  230. " <td>29</td>\n",
  231. " <td>137</td>\n",
  232. " <td>28</td>\n",
  233. " <td>40</td>\n",
  234. " <td>4</td>\n",
  235. " <td>...</td>\n",
  236. " <td>19.0</td>\n",
  237. " <td>3.0</td>\n",
  238. " <td>1.0</td>\n",
  239. " <td>2</td>\n",
  240. " <td>5.0</td>\n",
  241. " <td>NaN</td>\n",
  242. " <td>NaN</td>\n",
  243. " <td>NaN</td>\n",
  244. " <td>NaN</td>\n",
  245. " <td>NaN</td>\n",
  246. " </tr>\n",
  247. " <tr>\n",
  248. " <th>3</th>\n",
  249. " <td>allisdo01</td>\n",
  250. " <td>1871</td>\n",
  251. " <td>1</td>\n",
  252. " <td>WS3</td>\n",
  253. " <td>NaN</td>\n",
  254. " <td>27</td>\n",
  255. " <td>133</td>\n",
  256. " <td>28</td>\n",
  257. " <td>44</td>\n",
  258. " <td>10</td>\n",
  259. " <td>...</td>\n",
  260. " <td>27.0</td>\n",
  261. " <td>1.0</td>\n",
  262. " <td>1.0</td>\n",
  263. " <td>0</td>\n",
  264. " <td>2.0</td>\n",
  265. " <td>NaN</td>\n",
  266. " <td>NaN</td>\n",
  267. " <td>NaN</td>\n",
  268. " <td>NaN</td>\n",
  269. " <td>NaN</td>\n",
  270. " </tr>\n",
  271. " <tr>\n",
  272. " <th>4</th>\n",
  273. " <td>ansonca01</td>\n",
  274. " <td>1871</td>\n",
  275. " <td>1</td>\n",
  276. " <td>RC1</td>\n",
  277. " <td>NaN</td>\n",
  278. " <td>25</td>\n",
  279. " <td>120</td>\n",
  280. " <td>29</td>\n",
  281. " <td>39</td>\n",
  282. " <td>11</td>\n",
  283. " <td>...</td>\n",
  284. " <td>16.0</td>\n",
  285. " <td>6.0</td>\n",
  286. " <td>2.0</td>\n",
  287. " <td>2</td>\n",
  288. " <td>1.0</td>\n",
  289. " <td>NaN</td>\n",
  290. " <td>NaN</td>\n",
  291. " <td>NaN</td>\n",
  292. " <td>NaN</td>\n",
  293. " <td>NaN</td>\n",
  294. " </tr>\n",
  295. " <tr>\n",
  296. " <th>5</th>\n",
  297. " <td>armstbo01</td>\n",
  298. " <td>1871</td>\n",
  299. " <td>1</td>\n",
  300. " <td>FW1</td>\n",
  301. " <td>NaN</td>\n",
  302. " <td>12</td>\n",
  303. " <td>49</td>\n",
  304. " <td>9</td>\n",
  305. " <td>11</td>\n",
  306. " <td>2</td>\n",
  307. " <td>...</td>\n",
  308. " <td>5.0</td>\n",
  309. " <td>0.0</td>\n",
  310. " <td>1.0</td>\n",
  311. " <td>0</td>\n",
  312. " <td>1.0</td>\n",
  313. " <td>NaN</td>\n",
  314. " <td>NaN</td>\n",
  315. " <td>NaN</td>\n",
  316. " <td>NaN</td>\n",
  317. " <td>NaN</td>\n",
  318. " </tr>\n",
  319. " <tr>\n",
  320. " <th>6</th>\n",
  321. " <td>barkeal01</td>\n",
  322. " <td>1871</td>\n",
  323. " <td>1</td>\n",
  324. " <td>RC1</td>\n",
  325. " <td>NaN</td>\n",
  326. " <td>1</td>\n",
  327. " <td>4</td>\n",
  328. " <td>0</td>\n",
  329. " <td>1</td>\n",
  330. " <td>0</td>\n",
  331. " <td>...</td>\n",
  332. " <td>2.0</td>\n",
  333. " <td>0.0</td>\n",
  334. " <td>0.0</td>\n",
  335. " <td>1</td>\n",
  336. " <td>0.0</td>\n",
  337. " <td>NaN</td>\n",
  338. " <td>NaN</td>\n",
  339. " <td>NaN</td>\n",
  340. " <td>NaN</td>\n",
  341. " <td>NaN</td>\n",
  342. " </tr>\n",
  343. " <tr>\n",
  344. " <th>7</th>\n",
  345. " <td>barnero01</td>\n",
  346. " <td>1871</td>\n",
  347. " <td>1</td>\n",
  348. " <td>BS1</td>\n",
  349. " <td>NaN</td>\n",
  350. " <td>31</td>\n",
  351. " <td>157</td>\n",
  352. " <td>66</td>\n",
  353. " <td>63</td>\n",
  354. " <td>10</td>\n",
  355. " <td>...</td>\n",
  356. " <td>34.0</td>\n",
  357. " <td>11.0</td>\n",
  358. " <td>6.0</td>\n",
  359. " <td>13</td>\n",
  360. " <td>1.0</td>\n",
  361. " <td>NaN</td>\n",
  362. " <td>NaN</td>\n",
  363. " <td>NaN</td>\n",
  364. " <td>NaN</td>\n",
  365. " <td>NaN</td>\n",
  366. " </tr>\n",
  367. " <tr>\n",
  368. " <th>8</th>\n",
  369. " <td>barrebi01</td>\n",
  370. " <td>1871</td>\n",
  371. " <td>1</td>\n",
  372. " <td>FW1</td>\n",
  373. " <td>NaN</td>\n",
  374. " <td>1</td>\n",
  375. " <td>5</td>\n",
  376. " <td>1</td>\n",
  377. " <td>1</td>\n",
  378. " <td>1</td>\n",
  379. " <td>...</td>\n",
  380. " <td>1.0</td>\n",
  381. " <td>0.0</td>\n",
  382. " <td>0.0</td>\n",
  383. " <td>0</td>\n",
  384. " <td>0.0</td>\n",
  385. " <td>NaN</td>\n",
  386. " <td>NaN</td>\n",
  387. " <td>NaN</td>\n",
  388. " <td>NaN</td>\n",
  389. " <td>NaN</td>\n",
  390. " </tr>\n",
  391. " <tr>\n",
  392. " <th>9</th>\n",
  393. " <td>barrofr01</td>\n",
  394. " <td>1871</td>\n",
  395. " <td>1</td>\n",
  396. " <td>BS1</td>\n",
  397. " <td>NaN</td>\n",
  398. " <td>18</td>\n",
  399. " <td>86</td>\n",
  400. " <td>13</td>\n",
  401. " <td>13</td>\n",
  402. " <td>2</td>\n",
  403. " <td>...</td>\n",
  404. " <td>11.0</td>\n",
  405. " <td>1.0</td>\n",
  406. " <td>0.0</td>\n",
  407. " <td>0</td>\n",
  408. " <td>0.0</td>\n",
  409. " <td>NaN</td>\n",
  410. " <td>NaN</td>\n",
  411. " <td>NaN</td>\n",
  412. " <td>NaN</td>\n",
  413. " <td>NaN</td>\n",
  414. " </tr>\n",
  415. " <tr>\n",
  416. " <th>10</th>\n",
  417. " <td>bassjo01</td>\n",
  418. " <td>1871</td>\n",
  419. " <td>1</td>\n",
  420. " <td>CL1</td>\n",
  421. " <td>NaN</td>\n",
  422. " <td>22</td>\n",
  423. " <td>89</td>\n",
  424. " <td>18</td>\n",
  425. " <td>27</td>\n",
  426. " <td>1</td>\n",
  427. " <td>...</td>\n",
  428. " <td>18.0</td>\n",
  429. " <td>0.0</td>\n",
  430. " <td>1.0</td>\n",
  431. " <td>3</td>\n",
  432. " <td>4.0</td>\n",
  433. " <td>NaN</td>\n",
  434. " <td>NaN</td>\n",
  435. " <td>NaN</td>\n",
  436. " <td>NaN</td>\n",
  437. " <td>NaN</td>\n",
  438. " </tr>\n",
  439. " <tr>\n",
  440. " <th>11</th>\n",
  441. " <td>battijo01</td>\n",
  442. " <td>1871</td>\n",
  443. " <td>1</td>\n",
  444. " <td>CL1</td>\n",
  445. " <td>NaN</td>\n",
  446. " <td>1</td>\n",
  447. " <td>3</td>\n",
  448. " <td>0</td>\n",
  449. " <td>0</td>\n",
  450. " <td>0</td>\n",
  451. " <td>...</td>\n",
  452. " <td>0.0</td>\n",
  453. " <td>0.0</td>\n",
  454. " <td>0.0</td>\n",
  455. " <td>1</td>\n",
  456. " <td>0.0</td>\n",
  457. " <td>NaN</td>\n",
  458. " <td>NaN</td>\n",
  459. " <td>NaN</td>\n",
  460. " <td>NaN</td>\n",
  461. " <td>NaN</td>\n",
  462. " </tr>\n",
  463. " <tr>\n",
  464. " <th>12</th>\n",
  465. " <td>bealsto01</td>\n",
  466. " <td>1871</td>\n",
  467. " <td>1</td>\n",
  468. " <td>WS3</td>\n",
  469. " <td>NaN</td>\n",
  470. " <td>10</td>\n",
  471. " <td>36</td>\n",
  472. " <td>6</td>\n",
  473. " <td>7</td>\n",
  474. " <td>0</td>\n",
  475. " <td>...</td>\n",
  476. " <td>1.0</td>\n",
  477. " <td>2.0</td>\n",
  478. " <td>0.0</td>\n",
  479. " <td>2</td>\n",
  480. " <td>0.0</td>\n",
  481. " <td>NaN</td>\n",
  482. " <td>NaN</td>\n",
  483. " <td>NaN</td>\n",
  484. " <td>NaN</td>\n",
  485. " <td>NaN</td>\n",
  486. " </tr>\n",
  487. " <tr>\n",
  488. " <th>13</th>\n",
  489. " <td>beaveed01</td>\n",
  490. " <td>1871</td>\n",
  491. " <td>1</td>\n",
  492. " <td>TRO</td>\n",
  493. " <td>NaN</td>\n",
  494. " <td>3</td>\n",
  495. " <td>15</td>\n",
  496. " <td>7</td>\n",
  497. " <td>6</td>\n",
  498. " <td>0</td>\n",
  499. " <td>...</td>\n",
  500. " <td>5.0</td>\n",
  501. " <td>2.0</td>\n",
  502. " <td>0.0</td>\n",
  503. " <td>0</td>\n",
  504. " <td>0.0</td>\n",
  505. " <td>NaN</td>\n",
  506. " <td>NaN</td>\n",
  507. " <td>NaN</td>\n",
  508. " <td>NaN</td>\n",
  509. " <td>NaN</td>\n",
  510. " </tr>\n",
  511. " <tr>\n",
  512. " <th>14</th>\n",
  513. " <td>bechtge01</td>\n",
  514. " <td>1871</td>\n",
  515. " <td>1</td>\n",
  516. " <td>PH1</td>\n",
  517. " <td>NaN</td>\n",
  518. " <td>20</td>\n",
  519. " <td>94</td>\n",
  520. " <td>24</td>\n",
  521. " <td>33</td>\n",
  522. " <td>9</td>\n",
  523. " <td>...</td>\n",
  524. " <td>21.0</td>\n",
  525. " <td>4.0</td>\n",
  526. " <td>0.0</td>\n",
  527. " <td>2</td>\n",
  528. " <td>2.0</td>\n",
  529. " <td>NaN</td>\n",
  530. " <td>NaN</td>\n",
  531. " <td>NaN</td>\n",
  532. " <td>NaN</td>\n",
  533. " <td>NaN</td>\n",
  534. " </tr>\n",
  535. " <tr>\n",
  536. " <th>15</th>\n",
  537. " <td>bellast01</td>\n",
  538. " <td>1871</td>\n",
  539. " <td>1</td>\n",
  540. " <td>TRO</td>\n",
  541. " <td>NaN</td>\n",
  542. " <td>29</td>\n",
  543. " <td>128</td>\n",
  544. " <td>26</td>\n",
  545. " <td>32</td>\n",
  546. " <td>3</td>\n",
  547. " <td>...</td>\n",
  548. " <td>23.0</td>\n",
  549. " <td>4.0</td>\n",
  550. " <td>4.0</td>\n",
  551. " <td>9</td>\n",
  552. " <td>2.0</td>\n",
  553. " <td>NaN</td>\n",
  554. " <td>NaN</td>\n",
  555. " <td>NaN</td>\n",
  556. " <td>NaN</td>\n",
  557. " <td>NaN</td>\n",
  558. " </tr>\n",
  559. " <tr>\n",
  560. " <th>16</th>\n",
  561. " <td>berkena01</td>\n",
  562. " <td>1871</td>\n",
  563. " <td>1</td>\n",
  564. " <td>PH1</td>\n",
  565. " <td>NaN</td>\n",
  566. " <td>1</td>\n",
  567. " <td>4</td>\n",
  568. " <td>0</td>\n",
  569. " <td>0</td>\n",
  570. " <td>0</td>\n",
  571. " <td>...</td>\n",
  572. " <td>0.0</td>\n",
  573. " <td>0.0</td>\n",
  574. " <td>0.0</td>\n",
  575. " <td>0</td>\n",
  576. " <td>3.0</td>\n",
  577. " <td>NaN</td>\n",
  578. " <td>NaN</td>\n",
  579. " <td>NaN</td>\n",
  580. " <td>NaN</td>\n",
  581. " <td>NaN</td>\n",
  582. " </tr>\n",
  583. " <tr>\n",
  584. " <th>17</th>\n",
  585. " <td>berryto01</td>\n",
  586. " <td>1871</td>\n",
  587. " <td>1</td>\n",
  588. " <td>PH1</td>\n",
  589. " <td>NaN</td>\n",
  590. " <td>1</td>\n",
  591. " <td>4</td>\n",
  592. " <td>0</td>\n",
  593. " <td>1</td>\n",
  594. " <td>0</td>\n",
  595. " <td>...</td>\n",
  596. " <td>0.0</td>\n",
  597. " <td>0.0</td>\n",
  598. " <td>0.0</td>\n",
  599. " <td>0</td>\n",
  600. " <td>0.0</td>\n",
  601. " <td>NaN</td>\n",
  602. " <td>NaN</td>\n",
  603. " <td>NaN</td>\n",
  604. " <td>NaN</td>\n",
  605. " <td>NaN</td>\n",
  606. " </tr>\n",
  607. " <tr>\n",
  608. " <th>18</th>\n",
  609. " <td>berthha01</td>\n",
  610. " <td>1871</td>\n",
  611. " <td>1</td>\n",
  612. " <td>WS3</td>\n",
  613. " <td>NaN</td>\n",
  614. " <td>17</td>\n",
  615. " <td>73</td>\n",
  616. " <td>17</td>\n",
  617. " <td>17</td>\n",
  618. " <td>1</td>\n",
  619. " <td>...</td>\n",
  620. " <td>8.0</td>\n",
  621. " <td>3.0</td>\n",
  622. " <td>1.0</td>\n",
  623. " <td>4</td>\n",
  624. " <td>2.0</td>\n",
  625. " <td>NaN</td>\n",
  626. " <td>NaN</td>\n",
  627. " <td>NaN</td>\n",
  628. " <td>NaN</td>\n",
  629. " <td>NaN</td>\n",
  630. " </tr>\n",
  631. " <tr>\n",
  632. " <th>19</th>\n",
  633. " <td>biermch01</td>\n",
  634. " <td>1871</td>\n",
  635. " <td>1</td>\n",
  636. " <td>FW1</td>\n",
  637. " <td>NaN</td>\n",
  638. " <td>1</td>\n",
  639. " <td>2</td>\n",
  640. " <td>0</td>\n",
  641. " <td>0</td>\n",
  642. " <td>0</td>\n",
  643. " <td>...</td>\n",
  644. " <td>0.0</td>\n",
  645. " <td>0.0</td>\n",
  646. " <td>0.0</td>\n",
  647. " <td>1</td>\n",
  648. " <td>0.0</td>\n",
  649. " <td>NaN</td>\n",
  650. " <td>NaN</td>\n",
  651. " <td>NaN</td>\n",
  652. " <td>NaN</td>\n",
  653. " <td>NaN</td>\n",
  654. " </tr>\n",
  655. " <tr>\n",
  656. " <th>20</th>\n",
  657. " <td>birdge01</td>\n",
  658. " <td>1871</td>\n",
  659. " <td>1</td>\n",
  660. " <td>RC1</td>\n",
  661. " <td>NaN</td>\n",
  662. " <td>25</td>\n",
  663. " <td>106</td>\n",
  664. " <td>19</td>\n",
  665. " <td>28</td>\n",
  666. " <td>2</td>\n",
  667. " <td>...</td>\n",
  668. " <td>13.0</td>\n",
  669. " <td>1.0</td>\n",
  670. " <td>0.0</td>\n",
  671. " <td>3</td>\n",
  672. " <td>2.0</td>\n",
  673. " <td>NaN</td>\n",
  674. " <td>NaN</td>\n",
  675. " <td>NaN</td>\n",
  676. " <td>NaN</td>\n",
  677. " <td>NaN</td>\n",
  678. " </tr>\n",
  679. " <tr>\n",
  680. " <th>21</th>\n",
  681. " <td>birdsda01</td>\n",
  682. " <td>1871</td>\n",
  683. " <td>1</td>\n",
  684. " <td>BS1</td>\n",
  685. " <td>NaN</td>\n",
  686. " <td>29</td>\n",
  687. " <td>152</td>\n",
  688. " <td>51</td>\n",
  689. " <td>46</td>\n",
  690. " <td>3</td>\n",
  691. " <td>...</td>\n",
  692. " <td>24.0</td>\n",
  693. " <td>6.0</td>\n",
  694. " <td>0.0</td>\n",
  695. " <td>4</td>\n",
  696. " <td>4.0</td>\n",
  697. " <td>NaN</td>\n",
  698. " <td>NaN</td>\n",
  699. " <td>NaN</td>\n",
  700. " <td>NaN</td>\n",
  701. " <td>NaN</td>\n",
  702. " </tr>\n",
  703. " <tr>\n",
  704. " <th>22</th>\n",
  705. " <td>brainas01</td>\n",
  706. " <td>1871</td>\n",
  707. " <td>1</td>\n",
  708. " <td>WS3</td>\n",
  709. " <td>NaN</td>\n",
  710. " <td>30</td>\n",
  711. " <td>134</td>\n",
  712. " <td>24</td>\n",
  713. " <td>30</td>\n",
  714. " <td>4</td>\n",
  715. " <td>...</td>\n",
  716. " <td>21.0</td>\n",
  717. " <td>4.0</td>\n",
  718. " <td>0.0</td>\n",
  719. " <td>7</td>\n",
  720. " <td>2.0</td>\n",
  721. " <td>NaN</td>\n",
  722. " <td>NaN</td>\n",
  723. " <td>NaN</td>\n",
  724. " <td>NaN</td>\n",
  725. " <td>NaN</td>\n",
  726. " </tr>\n",
  727. " <tr>\n",
  728. " <th>23</th>\n",
  729. " <td>brannmi01</td>\n",
  730. " <td>1871</td>\n",
  731. " <td>1</td>\n",
  732. " <td>CH1</td>\n",
  733. " <td>NaN</td>\n",
  734. " <td>3</td>\n",
  735. " <td>14</td>\n",
  736. " <td>2</td>\n",
  737. " <td>1</td>\n",
  738. " <td>0</td>\n",
  739. " <td>...</td>\n",
  740. " <td>0.0</td>\n",
  741. " <td>0.0</td>\n",
  742. " <td>0.0</td>\n",
  743. " <td>0</td>\n",
  744. " <td>0.0</td>\n",
  745. " <td>NaN</td>\n",
  746. " <td>NaN</td>\n",
  747. " <td>NaN</td>\n",
  748. " <td>NaN</td>\n",
  749. " <td>NaN</td>\n",
  750. " </tr>\n",
  751. " <tr>\n",
  752. " <th>24</th>\n",
  753. " <td>burrohe01</td>\n",
  754. " <td>1871</td>\n",
  755. " <td>1</td>\n",
  756. " <td>WS3</td>\n",
  757. " <td>NaN</td>\n",
  758. " <td>12</td>\n",
  759. " <td>63</td>\n",
  760. " <td>11</td>\n",
  761. " <td>15</td>\n",
  762. " <td>2</td>\n",
  763. " <td>...</td>\n",
  764. " <td>14.0</td>\n",
  765. " <td>0.0</td>\n",
  766. " <td>0.0</td>\n",
  767. " <td>1</td>\n",
  768. " <td>1.0</td>\n",
  769. " <td>NaN</td>\n",
  770. " <td>NaN</td>\n",
  771. " <td>NaN</td>\n",
  772. " <td>NaN</td>\n",
  773. " <td>NaN</td>\n",
  774. " </tr>\n",
  775. " <tr>\n",
  776. " <th>25</th>\n",
  777. " <td>careyto01</td>\n",
  778. " <td>1871</td>\n",
  779. " <td>1</td>\n",
  780. " <td>FW1</td>\n",
  781. " <td>NaN</td>\n",
  782. " <td>19</td>\n",
  783. " <td>87</td>\n",
  784. " <td>16</td>\n",
  785. " <td>20</td>\n",
  786. " <td>2</td>\n",
  787. " <td>...</td>\n",
  788. " <td>10.0</td>\n",
  789. " <td>5.0</td>\n",
  790. " <td>0.0</td>\n",
  791. " <td>2</td>\n",
  792. " <td>1.0</td>\n",
  793. " <td>NaN</td>\n",
  794. " <td>NaN</td>\n",
  795. " <td>NaN</td>\n",
  796. " <td>NaN</td>\n",
  797. " <td>NaN</td>\n",
  798. " </tr>\n",
  799. " <tr>\n",
  800. " <th>26</th>\n",
  801. " <td>carleji01</td>\n",
  802. " <td>1871</td>\n",
  803. " <td>1</td>\n",
  804. " <td>CL1</td>\n",
  805. " <td>NaN</td>\n",
  806. " <td>29</td>\n",
  807. " <td>127</td>\n",
  808. " <td>31</td>\n",
  809. " <td>32</td>\n",
  810. " <td>8</td>\n",
  811. " <td>...</td>\n",
  812. " <td>18.0</td>\n",
  813. " <td>2.0</td>\n",
  814. " <td>1.0</td>\n",
  815. " <td>8</td>\n",
  816. " <td>3.0</td>\n",
  817. " <td>NaN</td>\n",
  818. " <td>NaN</td>\n",
  819. " <td>NaN</td>\n",
  820. " <td>NaN</td>\n",
  821. " <td>NaN</td>\n",
  822. " </tr>\n",
  823. " <tr>\n",
  824. " <th>27</th>\n",
  825. " <td>conefr01</td>\n",
  826. " <td>1871</td>\n",
  827. " <td>1</td>\n",
  828. " <td>BS1</td>\n",
  829. " <td>NaN</td>\n",
  830. " <td>19</td>\n",
  831. " <td>77</td>\n",
  832. " <td>17</td>\n",
  833. " <td>20</td>\n",
  834. " <td>3</td>\n",
  835. " <td>...</td>\n",
  836. " <td>16.0</td>\n",
  837. " <td>12.0</td>\n",
  838. " <td>1.0</td>\n",
  839. " <td>8</td>\n",
  840. " <td>2.0</td>\n",
  841. " <td>NaN</td>\n",
  842. " <td>NaN</td>\n",
  843. " <td>NaN</td>\n",
  844. " <td>NaN</td>\n",
  845. " <td>NaN</td>\n",
  846. " </tr>\n",
  847. " <tr>\n",
  848. " <th>28</th>\n",
  849. " <td>connone01</td>\n",
  850. " <td>1871</td>\n",
  851. " <td>1</td>\n",
  852. " <td>TRO</td>\n",
  853. " <td>NaN</td>\n",
  854. " <td>7</td>\n",
  855. " <td>33</td>\n",
  856. " <td>6</td>\n",
  857. " <td>7</td>\n",
  858. " <td>0</td>\n",
  859. " <td>...</td>\n",
  860. " <td>2.0</td>\n",
  861. " <td>0.0</td>\n",
  862. " <td>0.0</td>\n",
  863. " <td>0</td>\n",
  864. " <td>0.0</td>\n",
  865. " <td>NaN</td>\n",
  866. " <td>NaN</td>\n",
  867. " <td>NaN</td>\n",
  868. " <td>NaN</td>\n",
  869. " <td>NaN</td>\n",
  870. " </tr>\n",
  871. " <tr>\n",
  872. " <th>29</th>\n",
  873. " <td>cravebi01</td>\n",
  874. " <td>1871</td>\n",
  875. " <td>1</td>\n",
  876. " <td>TRO</td>\n",
  877. " <td>NaN</td>\n",
  878. " <td>27</td>\n",
  879. " <td>118</td>\n",
  880. " <td>26</td>\n",
  881. " <td>38</td>\n",
  882. " <td>8</td>\n",
  883. " <td>...</td>\n",
  884. " <td>26.0</td>\n",
  885. " <td>6.0</td>\n",
  886. " <td>3.0</td>\n",
  887. " <td>3</td>\n",
  888. " <td>0.0</td>\n",
  889. " <td>NaN</td>\n",
  890. " <td>NaN</td>\n",
  891. " <td>NaN</td>\n",
  892. " <td>NaN</td>\n",
  893. " <td>NaN</td>\n",
  894. " </tr>\n",
  895. " <tr>\n",
  896. " <th>...</th>\n",
  897. " <td>...</td>\n",
  898. " <td>...</td>\n",
  899. " <td>...</td>\n",
  900. " <td>...</td>\n",
  901. " <td>...</td>\n",
  902. " <td>...</td>\n",
  903. " <td>...</td>\n",
  904. " <td>...</td>\n",
  905. " <td>...</td>\n",
  906. " <td>...</td>\n",
  907. " <td>...</td>\n",
  908. " <td>...</td>\n",
  909. " <td>...</td>\n",
  910. " <td>...</td>\n",
  911. " <td>...</td>\n",
  912. " <td>...</td>\n",
  913. " <td>...</td>\n",
  914. " <td>...</td>\n",
  915. " <td>...</td>\n",
  916. " <td>...</td>\n",
  917. " <td>...</td>\n",
  918. " </tr>\n",
  919. " <tr>\n",
  920. " <th>102786</th>\n",
  921. " <td>wittgni01</td>\n",
  922. " <td>2016</td>\n",
  923. " <td>1</td>\n",
  924. " <td>MIA</td>\n",
  925. " <td>NL</td>\n",
  926. " <td>48</td>\n",
  927. " <td>0</td>\n",
  928. " <td>0</td>\n",
  929. " <td>0</td>\n",
  930. " <td>0</td>\n",
  931. " <td>...</td>\n",
  932. " <td>0.0</td>\n",
  933. " <td>0.0</td>\n",
  934. " <td>0.0</td>\n",
  935. " <td>0</td>\n",
  936. " <td>0.0</td>\n",
  937. " <td>0.0</td>\n",
  938. " <td>0.0</td>\n",
  939. " <td>0.0</td>\n",
  940. " <td>0.0</td>\n",
  941. " <td>0.0</td>\n",
  942. " </tr>\n",
  943. " <tr>\n",
  944. " <th>102787</th>\n",
  945. " <td>wolteto01</td>\n",
  946. " <td>2016</td>\n",
  947. " <td>1</td>\n",
  948. " <td>COL</td>\n",
  949. " <td>NL</td>\n",
  950. " <td>71</td>\n",
  951. " <td>205</td>\n",
  952. " <td>27</td>\n",
  953. " <td>53</td>\n",
  954. " <td>15</td>\n",
  955. " <td>...</td>\n",
  956. " <td>30.0</td>\n",
  957. " <td>4.0</td>\n",
  958. " <td>1.0</td>\n",
  959. " <td>21</td>\n",
  960. " <td>53.0</td>\n",
  961. " <td>2.0</td>\n",
  962. " <td>0.0</td>\n",
  963. " <td>4.0</td>\n",
  964. " <td>0.0</td>\n",
  965. " <td>1.0</td>\n",
  966. " </tr>\n",
  967. " <tr>\n",
  968. " <th>102788</th>\n",
  969. " <td>wongko01</td>\n",
  970. " <td>2016</td>\n",
  971. " <td>1</td>\n",
  972. " <td>SLN</td>\n",
  973. " <td>NL</td>\n",
  974. " <td>121</td>\n",
  975. " <td>313</td>\n",
  976. " <td>39</td>\n",
  977. " <td>75</td>\n",
  978. " <td>7</td>\n",
  979. " <td>...</td>\n",
  980. " <td>23.0</td>\n",
  981. " <td>7.0</td>\n",
  982. " <td>0.0</td>\n",
  983. " <td>34</td>\n",
  984. " <td>52.0</td>\n",
  985. " <td>2.0</td>\n",
  986. " <td>9.0</td>\n",
  987. " <td>0.0</td>\n",
  988. " <td>5.0</td>\n",
  989. " <td>3.0</td>\n",
  990. " </tr>\n",
  991. " <tr>\n",
  992. " <th>102789</th>\n",
  993. " <td>woodal02</td>\n",
  994. " <td>2016</td>\n",
  995. " <td>1</td>\n",
  996. " <td>LAN</td>\n",
  997. " <td>NL</td>\n",
  998. " <td>15</td>\n",
  999. " <td>16</td>\n",
  1000. " <td>2</td>\n",
  1001. " <td>4</td>\n",
  1002. " <td>0</td>\n",
  1003. " <td>...</td>\n",
  1004. " <td>2.0</td>\n",
  1005. " <td>0.0</td>\n",
  1006. " <td>0.0</td>\n",
  1007. " <td>1</td>\n",
  1008. " <td>9.0</td>\n",
  1009. " <td>0.0</td>\n",
  1010. " <td>0.0</td>\n",
  1011. " <td>2.0</td>\n",
  1012. " <td>0.0</td>\n",
  1013. " <td>0.0</td>\n",
  1014. " </tr>\n",
  1015. " <tr>\n",
  1016. " <th>102790</th>\n",
  1017. " <td>woodbl01</td>\n",
  1018. " <td>2016</td>\n",
  1019. " <td>1</td>\n",
  1020. " <td>CIN</td>\n",
  1021. " <td>NL</td>\n",
  1022. " <td>70</td>\n",
  1023. " <td>2</td>\n",
  1024. " <td>0</td>\n",
  1025. " <td>0</td>\n",
  1026. " <td>0</td>\n",
  1027. " <td>...</td>\n",
  1028. " <td>0.0</td>\n",
  1029. " <td>0.0</td>\n",
  1030. " <td>0.0</td>\n",
  1031. " <td>0</td>\n",
  1032. " <td>2.0</td>\n",
  1033. " <td>0.0</td>\n",
  1034. " <td>0.0</td>\n",
  1035. " <td>0.0</td>\n",
  1036. " <td>0.0</td>\n",
  1037. " <td>0.0</td>\n",
  1038. " </tr>\n",
  1039. " <tr>\n",
  1040. " <th>102791</th>\n",
  1041. " <td>woodtr01</td>\n",
  1042. " <td>2016</td>\n",
  1043. " <td>1</td>\n",
  1044. " <td>CHN</td>\n",
  1045. " <td>NL</td>\n",
  1046. " <td>81</td>\n",
  1047. " <td>11</td>\n",
  1048. " <td>0</td>\n",
  1049. " <td>2</td>\n",
  1050. " <td>0</td>\n",
  1051. " <td>...</td>\n",
  1052. " <td>1.0</td>\n",
  1053. " <td>0.0</td>\n",
  1054. " <td>0.0</td>\n",
  1055. " <td>1</td>\n",
  1056. " <td>5.0</td>\n",
  1057. " <td>0.0</td>\n",
  1058. " <td>0.0</td>\n",
  1059. " <td>0.0</td>\n",
  1060. " <td>0.0</td>\n",
  1061. " <td>0.0</td>\n",
  1062. " </tr>\n",
  1063. " <tr>\n",
  1064. " <th>102792</th>\n",
  1065. " <td>worleva01</td>\n",
  1066. " <td>2016</td>\n",
  1067. " <td>1</td>\n",
  1068. " <td>BAL</td>\n",
  1069. " <td>AL</td>\n",
  1070. " <td>35</td>\n",
  1071. " <td>0</td>\n",
  1072. " <td>0</td>\n",
  1073. " <td>0</td>\n",
  1074. " <td>0</td>\n",
  1075. " <td>...</td>\n",
  1076. " <td>0.0</td>\n",
  1077. " <td>0.0</td>\n",
  1078. " <td>0.0</td>\n",
  1079. " <td>0</td>\n",
  1080. " <td>0.0</td>\n",
  1081. " <td>0.0</td>\n",
  1082. " <td>0.0</td>\n",
  1083. " <td>0.0</td>\n",
  1084. " <td>0.0</td>\n",
  1085. " <td>0.0</td>\n",
  1086. " </tr>\n",
  1087. " <tr>\n",
  1088. " <th>102793</th>\n",
  1089. " <td>worthda01</td>\n",
  1090. " <td>2016</td>\n",
  1091. " <td>1</td>\n",
  1092. " <td>HOU</td>\n",
  1093. " <td>AL</td>\n",
  1094. " <td>16</td>\n",
  1095. " <td>39</td>\n",
  1096. " <td>4</td>\n",
  1097. " <td>7</td>\n",
  1098. " <td>2</td>\n",
  1099. " <td>...</td>\n",
  1100. " <td>1.0</td>\n",
  1101. " <td>0.0</td>\n",
  1102. " <td>0.0</td>\n",
  1103. " <td>1</td>\n",
  1104. " <td>6.0</td>\n",
  1105. " <td>0.0</td>\n",
  1106. " <td>0.0</td>\n",
  1107. " <td>0.0</td>\n",
  1108. " <td>0.0</td>\n",
  1109. " <td>1.0</td>\n",
  1110. " </tr>\n",
  1111. " <tr>\n",
  1112. " <th>102794</th>\n",
  1113. " <td>wrighda03</td>\n",
  1114. " <td>2016</td>\n",
  1115. " <td>1</td>\n",
  1116. " <td>NYN</td>\n",
  1117. " <td>NL</td>\n",
  1118. " <td>37</td>\n",
  1119. " <td>137</td>\n",
  1120. " <td>18</td>\n",
  1121. " <td>31</td>\n",
  1122. " <td>8</td>\n",
  1123. " <td>...</td>\n",
  1124. " <td>14.0</td>\n",
  1125. " <td>3.0</td>\n",
  1126. " <td>2.0</td>\n",
  1127. " <td>26</td>\n",
  1128. " <td>55.0</td>\n",
  1129. " <td>0.0</td>\n",
  1130. " <td>0.0</td>\n",
  1131. " <td>0.0</td>\n",
  1132. " <td>0.0</td>\n",
  1133. " <td>0.0</td>\n",
  1134. " </tr>\n",
  1135. " <tr>\n",
  1136. " <th>102795</th>\n",
  1137. " <td>wrighda04</td>\n",
  1138. " <td>2016</td>\n",
  1139. " <td>1</td>\n",
  1140. " <td>CIN</td>\n",
  1141. " <td>NL</td>\n",
  1142. " <td>4</td>\n",
  1143. " <td>5</td>\n",
  1144. " <td>0</td>\n",
  1145. " <td>0</td>\n",
  1146. " <td>0</td>\n",
  1147. " <td>...</td>\n",
  1148. " <td>0.0</td>\n",
  1149. " <td>0.0</td>\n",
  1150. " <td>0.0</td>\n",
  1151. " <td>0</td>\n",
  1152. " <td>2.0</td>\n",
  1153. " <td>0.0</td>\n",
  1154. " <td>0.0</td>\n",
  1155. " <td>1.0</td>\n",
  1156. " <td>0.0</td>\n",
  1157. " <td>0.0</td>\n",
  1158. " </tr>\n",
  1159. " <tr>\n",
  1160. " <th>102796</th>\n",
  1161. " <td>wrighda04</td>\n",
  1162. " <td>2016</td>\n",
  1163. " <td>2</td>\n",
  1164. " <td>LAA</td>\n",
  1165. " <td>AL</td>\n",
  1166. " <td>5</td>\n",
  1167. " <td>0</td>\n",
  1168. " <td>0</td>\n",
  1169. " <td>0</td>\n",
  1170. " <td>0</td>\n",
  1171. " <td>...</td>\n",
  1172. " <td>0.0</td>\n",
  1173. " <td>0.0</td>\n",
  1174. " <td>0.0</td>\n",
  1175. " <td>0</td>\n",
  1176. " <td>0.0</td>\n",
  1177. " <td>0.0</td>\n",
  1178. " <td>0.0</td>\n",
  1179. " <td>0.0</td>\n",
  1180. " <td>0.0</td>\n",
  1181. " <td>0.0</td>\n",
  1182. " </tr>\n",
  1183. " <tr>\n",
  1184. " <th>102797</th>\n",
  1185. " <td>wrighmi01</td>\n",
  1186. " <td>2016</td>\n",
  1187. " <td>1</td>\n",
  1188. " <td>BAL</td>\n",
  1189. " <td>AL</td>\n",
  1190. " <td>18</td>\n",
  1191. " <td>0</td>\n",
  1192. " <td>0</td>\n",
  1193. " <td>0</td>\n",
  1194. " <td>0</td>\n",
  1195. " <td>...</td>\n",
  1196. " <td>0.0</td>\n",
  1197. " <td>0.0</td>\n",
  1198. " <td>0.0</td>\n",
  1199. " <td>0</td>\n",
  1200. " <td>0.0</td>\n",
  1201. " <td>0.0</td>\n",
  1202. " <td>0.0</td>\n",
  1203. " <td>0.0</td>\n",
  1204. " <td>0.0</td>\n",
  1205. " <td>0.0</td>\n",
  1206. " </tr>\n",
  1207. " <tr>\n",
  1208. " <th>102798</th>\n",
  1209. " <td>wrighst01</td>\n",
  1210. " <td>2016</td>\n",
  1211. " <td>1</td>\n",
  1212. " <td>BOS</td>\n",
  1213. " <td>AL</td>\n",
  1214. " <td>25</td>\n",
  1215. " <td>4</td>\n",
  1216. " <td>0</td>\n",
  1217. " <td>0</td>\n",
  1218. " <td>0</td>\n",
  1219. " <td>...</td>\n",
  1220. " <td>0.0</td>\n",
  1221. " <td>0.0</td>\n",
  1222. " <td>0.0</td>\n",
  1223. " <td>0</td>\n",
  1224. " <td>3.0</td>\n",
  1225. " <td>0.0</td>\n",
  1226. " <td>0.0</td>\n",
  1227. " <td>0.0</td>\n",
  1228. " <td>0.0</td>\n",
  1229. " <td>0.0</td>\n",
  1230. " </tr>\n",
  1231. " <tr>\n",
  1232. " <th>102799</th>\n",
  1233. " <td>yateski01</td>\n",
  1234. " <td>2016</td>\n",
  1235. " <td>1</td>\n",
  1236. " <td>NYA</td>\n",
  1237. " <td>AL</td>\n",
  1238. " <td>41</td>\n",
  1239. " <td>0</td>\n",
  1240. " <td>0</td>\n",
  1241. " <td>0</td>\n",
  1242. " <td>0</td>\n",
  1243. " <td>...</td>\n",
  1244. " <td>0.0</td>\n",
  1245. " <td>0.0</td>\n",
  1246. " <td>0.0</td>\n",
  1247. " <td>0</td>\n",
  1248. " <td>0.0</td>\n",
  1249. " <td>0.0</td>\n",
  1250. " <td>0.0</td>\n",
  1251. " <td>0.0</td>\n",
  1252. " <td>0.0</td>\n",
  1253. " <td>0.0</td>\n",
  1254. " </tr>\n",
  1255. " <tr>\n",
  1256. " <th>102800</th>\n",
  1257. " <td>yelicch01</td>\n",
  1258. " <td>2016</td>\n",
  1259. " <td>1</td>\n",
  1260. " <td>MIA</td>\n",
  1261. " <td>NL</td>\n",
  1262. " <td>155</td>\n",
  1263. " <td>578</td>\n",
  1264. " <td>78</td>\n",
  1265. " <td>172</td>\n",
  1266. " <td>38</td>\n",
  1267. " <td>...</td>\n",
  1268. " <td>98.0</td>\n",
  1269. " <td>9.0</td>\n",
  1270. " <td>4.0</td>\n",
  1271. " <td>72</td>\n",
  1272. " <td>138.0</td>\n",
  1273. " <td>4.0</td>\n",
  1274. " <td>4.0</td>\n",
  1275. " <td>0.0</td>\n",
  1276. " <td>5.0</td>\n",
  1277. " <td>20.0</td>\n",
  1278. " </tr>\n",
  1279. " <tr>\n",
  1280. " <th>102801</th>\n",
  1281. " <td>ynoaga01</td>\n",
  1282. " <td>2016</td>\n",
  1283. " <td>1</td>\n",
  1284. " <td>NYN</td>\n",
  1285. " <td>NL</td>\n",
  1286. " <td>10</td>\n",
  1287. " <td>3</td>\n",
  1288. " <td>0</td>\n",
  1289. " <td>0</td>\n",
  1290. " <td>0</td>\n",
  1291. " <td>...</td>\n",
  1292. " <td>0.0</td>\n",
  1293. " <td>0.0</td>\n",
  1294. " <td>0.0</td>\n",
  1295. " <td>0</td>\n",
  1296. " <td>0.0</td>\n",
  1297. " <td>0.0</td>\n",
  1298. " <td>0.0</td>\n",
  1299. " <td>0.0</td>\n",
  1300. " <td>0.0</td>\n",
  1301. " <td>0.0</td>\n",
  1302. " </tr>\n",
  1303. " <tr>\n",
  1304. " <th>102802</th>\n",
  1305. " <td>ynoami01</td>\n",
  1306. " <td>2016</td>\n",
  1307. " <td>1</td>\n",
  1308. " <td>CHA</td>\n",
  1309. " <td>AL</td>\n",
  1310. " <td>23</td>\n",
  1311. " <td>0</td>\n",
  1312. " <td>0</td>\n",
  1313. " <td>0</td>\n",
  1314. " <td>0</td>\n",
  1315. " <td>...</td>\n",
  1316. " <td>0.0</td>\n",
  1317. " <td>0.0</td>\n",
  1318. " <td>0.0</td>\n",
  1319. " <td>0</td>\n",
  1320. " <td>0.0</td>\n",
  1321. " <td>0.0</td>\n",
  1322. " <td>0.0</td>\n",
  1323. " <td>0.0</td>\n",
  1324. " <td>0.0</td>\n",
  1325. " <td>0.0</td>\n",
  1326. " </tr>\n",
  1327. " <tr>\n",
  1328. " <th>102803</th>\n",
  1329. " <td>ynoara01</td>\n",
  1330. " <td>2016</td>\n",
  1331. " <td>1</td>\n",
  1332. " <td>COL</td>\n",
  1333. " <td>NL</td>\n",
  1334. " <td>3</td>\n",
  1335. " <td>5</td>\n",
  1336. " <td>0</td>\n",
  1337. " <td>0</td>\n",
  1338. " <td>0</td>\n",
  1339. " <td>...</td>\n",
  1340. " <td>0.0</td>\n",
  1341. " <td>0.0</td>\n",
  1342. " <td>0.0</td>\n",
  1343. " <td>0</td>\n",
  1344. " <td>2.0</td>\n",
  1345. " <td>0.0</td>\n",
  1346. " <td>0.0</td>\n",
  1347. " <td>0.0</td>\n",
  1348. " <td>0.0</td>\n",
  1349. " <td>0.0</td>\n",
  1350. " </tr>\n",
  1351. " <tr>\n",
  1352. " <th>102804</th>\n",
  1353. " <td>youngch03</td>\n",
  1354. " <td>2016</td>\n",
  1355. " <td>1</td>\n",
  1356. " <td>KCA</td>\n",
  1357. " <td>AL</td>\n",
  1358. " <td>34</td>\n",
  1359. " <td>1</td>\n",
  1360. " <td>0</td>\n",
  1361. " <td>0</td>\n",
  1362. " <td>0</td>\n",
  1363. " <td>...</td>\n",
  1364. " <td>0.0</td>\n",
  1365. " <td>0.0</td>\n",
  1366. " <td>0.0</td>\n",
  1367. " <td>0</td>\n",
  1368. " <td>0.0</td>\n",
  1369. " <td>0.0</td>\n",
  1370. " <td>0.0</td>\n",
  1371. " <td>0.0</td>\n",
  1372. " <td>0.0</td>\n",
  1373. " <td>0.0</td>\n",
  1374. " </tr>\n",
  1375. " <tr>\n",
  1376. " <th>102805</th>\n",
  1377. " <td>youngch04</td>\n",
  1378. " <td>2016</td>\n",
  1379. " <td>1</td>\n",
  1380. " <td>BOS</td>\n",
  1381. " <td>AL</td>\n",
  1382. " <td>76</td>\n",
  1383. " <td>203</td>\n",
  1384. " <td>29</td>\n",
  1385. " <td>56</td>\n",
  1386. " <td>18</td>\n",
  1387. " <td>...</td>\n",
  1388. " <td>24.0</td>\n",
  1389. " <td>4.0</td>\n",
  1390. " <td>2.0</td>\n",
  1391. " <td>21</td>\n",
  1392. " <td>50.0</td>\n",
  1393. " <td>0.0</td>\n",
  1394. " <td>3.0</td>\n",
  1395. " <td>0.0</td>\n",
  1396. " <td>0.0</td>\n",
  1397. " <td>4.0</td>\n",
  1398. " </tr>\n",
  1399. " <tr>\n",
  1400. " <th>102806</th>\n",
  1401. " <td>younger03</td>\n",
  1402. " <td>2016</td>\n",
  1403. " <td>1</td>\n",
  1404. " <td>NYA</td>\n",
  1405. " <td>AL</td>\n",
  1406. " <td>6</td>\n",
  1407. " <td>1</td>\n",
  1408. " <td>2</td>\n",
  1409. " <td>0</td>\n",
  1410. " <td>0</td>\n",
  1411. " <td>...</td>\n",
  1412. " <td>0.0</td>\n",
  1413. " <td>1.0</td>\n",
  1414. " <td>0.0</td>\n",
  1415. " <td>0</td>\n",
  1416. " <td>0.0</td>\n",
  1417. " <td>0.0</td>\n",
  1418. " <td>0.0</td>\n",
  1419. " <td>0.0</td>\n",
  1420. " <td>0.0</td>\n",
  1421. " <td>0.0</td>\n",
  1422. " </tr>\n",
  1423. " <tr>\n",
  1424. " <th>102807</th>\n",
  1425. " <td>youngma03</td>\n",
  1426. " <td>2016</td>\n",
  1427. " <td>1</td>\n",
  1428. " <td>ATL</td>\n",
  1429. " <td>NL</td>\n",
  1430. " <td>8</td>\n",
  1431. " <td>0</td>\n",
  1432. " <td>0</td>\n",
  1433. " <td>0</td>\n",
  1434. " <td>0</td>\n",
  1435. " <td>...</td>\n",
  1436. " <td>0.0</td>\n",
  1437. " <td>0.0</td>\n",
  1438. " <td>0.0</td>\n",
  1439. " <td>0</td>\n",
  1440. " <td>0.0</td>\n",
  1441. " <td>0.0</td>\n",
  1442. " <td>0.0</td>\n",
  1443. " <td>0.0</td>\n",
  1444. " <td>0.0</td>\n",
  1445. " <td>0.0</td>\n",
  1446. " </tr>\n",
  1447. " <tr>\n",
  1448. " <th>102808</th>\n",
  1449. " <td>zastrro01</td>\n",
  1450. " <td>2016</td>\n",
  1451. " <td>1</td>\n",
  1452. " <td>CHN</td>\n",
  1453. " <td>NL</td>\n",
  1454. " <td>8</td>\n",
  1455. " <td>3</td>\n",
  1456. " <td>0</td>\n",
  1457. " <td>0</td>\n",
  1458. " <td>0</td>\n",
  1459. " <td>...</td>\n",
  1460. " <td>0.0</td>\n",
  1461. " <td>0.0</td>\n",
  1462. " <td>0.0</td>\n",
  1463. " <td>0</td>\n",
  1464. " <td>2.0</td>\n",
  1465. " <td>0.0</td>\n",
  1466. " <td>0.0</td>\n",
  1467. " <td>0.0</td>\n",
  1468. " <td>0.0</td>\n",
  1469. " <td>0.0</td>\n",
  1470. " </tr>\n",
  1471. " <tr>\n",
  1472. " <th>102809</th>\n",
  1473. " <td>zieglbr01</td>\n",
  1474. " <td>2016</td>\n",
  1475. " <td>1</td>\n",
  1476. " <td>ARI</td>\n",
  1477. " <td>NL</td>\n",
  1478. " <td>36</td>\n",
  1479. " <td>0</td>\n",
  1480. " <td>0</td>\n",
  1481. " <td>0</td>\n",
  1482. " <td>0</td>\n",
  1483. " <td>...</td>\n",
  1484. " <td>0.0</td>\n",
  1485. " <td>0.0</td>\n",
  1486. " <td>0.0</td>\n",
  1487. " <td>0</td>\n",
  1488. " <td>0.0</td>\n",
  1489. " <td>0.0</td>\n",
  1490. " <td>0.0</td>\n",
  1491. " <td>0.0</td>\n",
  1492. " <td>0.0</td>\n",
  1493. " <td>0.0</td>\n",
  1494. " </tr>\n",
  1495. " <tr>\n",
  1496. " <th>102810</th>\n",
  1497. " <td>zieglbr01</td>\n",
  1498. " <td>2016</td>\n",
  1499. " <td>2</td>\n",
  1500. " <td>BOS</td>\n",
  1501. " <td>AL</td>\n",
  1502. " <td>33</td>\n",
  1503. " <td>0</td>\n",
  1504. " <td>0</td>\n",
  1505. " <td>0</td>\n",
  1506. " <td>0</td>\n",
  1507. " <td>...</td>\n",
  1508. " <td>0.0</td>\n",
  1509. " <td>0.0</td>\n",
  1510. " <td>0.0</td>\n",
  1511. " <td>0</td>\n",
  1512. " <td>0.0</td>\n",
  1513. " <td>0.0</td>\n",
  1514. " <td>0.0</td>\n",
  1515. " <td>0.0</td>\n",
  1516. " <td>0.0</td>\n",
  1517. " <td>0.0</td>\n",
  1518. " </tr>\n",
  1519. " <tr>\n",
  1520. " <th>102811</th>\n",
  1521. " <td>zimmejo02</td>\n",
  1522. " <td>2016</td>\n",
  1523. " <td>1</td>\n",
  1524. " <td>DET</td>\n",
  1525. " <td>AL</td>\n",
  1526. " <td>19</td>\n",
  1527. " <td>4</td>\n",
  1528. " <td>0</td>\n",
  1529. " <td>1</td>\n",
  1530. " <td>0</td>\n",
  1531. " <td>...</td>\n",
  1532. " <td>0.0</td>\n",
  1533. " <td>0.0</td>\n",
  1534. " <td>0.0</td>\n",
  1535. " <td>0</td>\n",
  1536. " <td>2.0</td>\n",
  1537. " <td>0.0</td>\n",
  1538. " <td>0.0</td>\n",
  1539. " <td>1.0</td>\n",
  1540. " <td>0.0</td>\n",
  1541. " <td>0.0</td>\n",
  1542. " </tr>\n",
  1543. " <tr>\n",
  1544. " <th>102812</th>\n",
  1545. " <td>zimmery01</td>\n",
  1546. " <td>2016</td>\n",
  1547. " <td>1</td>\n",
  1548. " <td>WAS</td>\n",
  1549. " <td>NL</td>\n",
  1550. " <td>115</td>\n",
  1551. " <td>427</td>\n",
  1552. " <td>60</td>\n",
  1553. " <td>93</td>\n",
  1554. " <td>18</td>\n",
  1555. " <td>...</td>\n",
  1556. " <td>46.0</td>\n",
  1557. " <td>4.0</td>\n",
  1558. " <td>1.0</td>\n",
  1559. " <td>29</td>\n",
  1560. " <td>104.0</td>\n",
  1561. " <td>1.0</td>\n",
  1562. " <td>5.0</td>\n",
  1563. " <td>0.0</td>\n",
  1564. " <td>6.0</td>\n",
  1565. " <td>12.0</td>\n",
  1566. " </tr>\n",
  1567. " <tr>\n",
  1568. " <th>102813</th>\n",
  1569. " <td>zobribe01</td>\n",
  1570. " <td>2016</td>\n",
  1571. " <td>1</td>\n",
  1572. " <td>CHN</td>\n",
  1573. " <td>NL</td>\n",
  1574. " <td>147</td>\n",
  1575. " <td>523</td>\n",
  1576. " <td>94</td>\n",
  1577. " <td>142</td>\n",
  1578. " <td>31</td>\n",
  1579. " <td>...</td>\n",
  1580. " <td>76.0</td>\n",
  1581. " <td>6.0</td>\n",
  1582. " <td>4.0</td>\n",
  1583. " <td>96</td>\n",
  1584. " <td>82.0</td>\n",
  1585. " <td>6.0</td>\n",
  1586. " <td>4.0</td>\n",
  1587. " <td>4.0</td>\n",
  1588. " <td>4.0</td>\n",
  1589. " <td>17.0</td>\n",
  1590. " </tr>\n",
  1591. " <tr>\n",
  1592. " <th>102814</th>\n",
  1593. " <td>zuninmi01</td>\n",
  1594. " <td>2016</td>\n",
  1595. " <td>1</td>\n",
  1596. " <td>SEA</td>\n",
  1597. " <td>AL</td>\n",
  1598. " <td>55</td>\n",
  1599. " <td>164</td>\n",
  1600. " <td>16</td>\n",
  1601. " <td>34</td>\n",
  1602. " <td>7</td>\n",
  1603. " <td>...</td>\n",
  1604. " <td>31.0</td>\n",
  1605. " <td>0.0</td>\n",
  1606. " <td>0.0</td>\n",
  1607. " <td>21</td>\n",
  1608. " <td>65.0</td>\n",
  1609. " <td>0.0</td>\n",
  1610. " <td>6.0</td>\n",
  1611. " <td>0.0</td>\n",
  1612. " <td>1.0</td>\n",
  1613. " <td>0.0</td>\n",
  1614. " </tr>\n",
  1615. " <tr>\n",
  1616. " <th>102815</th>\n",
  1617. " <td>zychto01</td>\n",
  1618. " <td>2016</td>\n",
  1619. " <td>1</td>\n",
  1620. " <td>SEA</td>\n",
  1621. " <td>AL</td>\n",
  1622. " <td>12</td>\n",
  1623. " <td>0</td>\n",
  1624. " <td>0</td>\n",
  1625. " <td>0</td>\n",
  1626. " <td>0</td>\n",
  1627. " <td>...</td>\n",
  1628. " <td>0.0</td>\n",
  1629. " <td>0.0</td>\n",
  1630. " <td>0.0</td>\n",
  1631. " <td>0</td>\n",
  1632. " <td>0.0</td>\n",
  1633. " <td>0.0</td>\n",
  1634. " <td>0.0</td>\n",
  1635. " <td>0.0</td>\n",
  1636. " <td>0.0</td>\n",
  1637. " <td>0.0</td>\n",
  1638. " </tr>\n",
  1639. " </tbody>\n",
  1640. "</table>\n",
  1641. "<p>102816 rows × 22 columns</p>\n",
  1642. "</div>"
  1643. ],
  1644. "text/plain": [
  1645. " playerID yearID stint teamID lgID G AB R H 2B ... \\\n",
  1646. "0 abercda01 1871 1 TRO NaN 1 4 0 0 0 ... \n",
  1647. "1 addybo01 1871 1 RC1 NaN 25 118 30 32 6 ... \n",
  1648. "2 allisar01 1871 1 CL1 NaN 29 137 28 40 4 ... \n",
  1649. "3 allisdo01 1871 1 WS3 NaN 27 133 28 44 10 ... \n",
  1650. "4 ansonca01 1871 1 RC1 NaN 25 120 29 39 11 ... \n",
  1651. "5 armstbo01 1871 1 FW1 NaN 12 49 9 11 2 ... \n",
  1652. "6 barkeal01 1871 1 RC1 NaN 1 4 0 1 0 ... \n",
  1653. "7 barnero01 1871 1 BS1 NaN 31 157 66 63 10 ... \n",
  1654. "8 barrebi01 1871 1 FW1 NaN 1 5 1 1 1 ... \n",
  1655. "9 barrofr01 1871 1 BS1 NaN 18 86 13 13 2 ... \n",
  1656. "10 bassjo01 1871 1 CL1 NaN 22 89 18 27 1 ... \n",
  1657. "11 battijo01 1871 1 CL1 NaN 1 3 0 0 0 ... \n",
  1658. "12 bealsto01 1871 1 WS3 NaN 10 36 6 7 0 ... \n",
  1659. "13 beaveed01 1871 1 TRO NaN 3 15 7 6 0 ... \n",
  1660. "14 bechtge01 1871 1 PH1 NaN 20 94 24 33 9 ... \n",
  1661. "15 bellast01 1871 1 TRO NaN 29 128 26 32 3 ... \n",
  1662. "16 berkena01 1871 1 PH1 NaN 1 4 0 0 0 ... \n",
  1663. "17 berryto01 1871 1 PH1 NaN 1 4 0 1 0 ... \n",
  1664. "18 berthha01 1871 1 WS3 NaN 17 73 17 17 1 ... \n",
  1665. "19 biermch01 1871 1 FW1 NaN 1 2 0 0 0 ... \n",
  1666. "20 birdge01 1871 1 RC1 NaN 25 106 19 28 2 ... \n",
  1667. "21 birdsda01 1871 1 BS1 NaN 29 152 51 46 3 ... \n",
  1668. "22 brainas01 1871 1 WS3 NaN 30 134 24 30 4 ... \n",
  1669. "23 brannmi01 1871 1 CH1 NaN 3 14 2 1 0 ... \n",
  1670. "24 burrohe01 1871 1 WS3 NaN 12 63 11 15 2 ... \n",
  1671. "25 careyto01 1871 1 FW1 NaN 19 87 16 20 2 ... \n",
  1672. "26 carleji01 1871 1 CL1 NaN 29 127 31 32 8 ... \n",
  1673. "27 conefr01 1871 1 BS1 NaN 19 77 17 20 3 ... \n",
  1674. "28 connone01 1871 1 TRO NaN 7 33 6 7 0 ... \n",
  1675. "29 cravebi01 1871 1 TRO NaN 27 118 26 38 8 ... \n",
  1676. "... ... ... ... ... ... ... ... .. ... .. ... \n",
  1677. "102786 wittgni01 2016 1 MIA NL 48 0 0 0 0 ... \n",
  1678. "102787 wolteto01 2016 1 COL NL 71 205 27 53 15 ... \n",
  1679. "102788 wongko01 2016 1 SLN NL 121 313 39 75 7 ... \n",
  1680. "102789 woodal02 2016 1 LAN NL 15 16 2 4 0 ... \n",
  1681. "102790 woodbl01 2016 1 CIN NL 70 2 0 0 0 ... \n",
  1682. "102791 woodtr01 2016 1 CHN NL 81 11 0 2 0 ... \n",
  1683. "102792 worleva01 2016 1 BAL AL 35 0 0 0 0 ... \n",
  1684. "102793 worthda01 2016 1 HOU AL 16 39 4 7 2 ... \n",
  1685. "102794 wrighda03 2016 1 NYN NL 37 137 18 31 8 ... \n",
  1686. "102795 wrighda04 2016 1 CIN NL 4 5 0 0 0 ... \n",
  1687. "102796 wrighda04 2016 2 LAA AL 5 0 0 0 0 ... \n",
  1688. "102797 wrighmi01 2016 1 BAL AL 18 0 0 0 0 ... \n",
  1689. "102798 wrighst01 2016 1 BOS AL 25 4 0 0 0 ... \n",
  1690. "102799 yateski01 2016 1 NYA AL 41 0 0 0 0 ... \n",
  1691. "102800 yelicch01 2016 1 MIA NL 155 578 78 172 38 ... \n",
  1692. "102801 ynoaga01 2016 1 NYN NL 10 3 0 0 0 ... \n",
  1693. "102802 ynoami01 2016 1 CHA AL 23 0 0 0 0 ... \n",
  1694. "102803 ynoara01 2016 1 COL NL 3 5 0 0 0 ... \n",
  1695. "102804 youngch03 2016 1 KCA AL 34 1 0 0 0 ... \n",
  1696. "102805 youngch04 2016 1 BOS AL 76 203 29 56 18 ... \n",
  1697. "102806 younger03 2016 1 NYA AL 6 1 2 0 0 ... \n",
  1698. "102807 youngma03 2016 1 ATL NL 8 0 0 0 0 ... \n",
  1699. "102808 zastrro01 2016 1 CHN NL 8 3 0 0 0 ... \n",
  1700. "102809 zieglbr01 2016 1 ARI NL 36 0 0 0 0 ... \n",
  1701. "102810 zieglbr01 2016 2 BOS AL 33 0 0 0 0 ... \n",
  1702. "102811 zimmejo02 2016 1 DET AL 19 4 0 1 0 ... \n",
  1703. "102812 zimmery01 2016 1 WAS NL 115 427 60 93 18 ... \n",
  1704. "102813 zobribe01 2016 1 CHN NL 147 523 94 142 31 ... \n",
  1705. "102814 zuninmi01 2016 1 SEA AL 55 164 16 34 7 ... \n",
  1706. "102815 zychto01 2016 1 SEA AL 12 0 0 0 0 ... \n",
  1707. "\n",
  1708. " RBI SB CS BB SO IBB HBP SH SF GIDP \n",
  1709. "0 0.0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1710. "1 13.0 8.0 1.0 4 0.0 NaN NaN NaN NaN NaN \n",
  1711. "2 19.0 3.0 1.0 2 5.0 NaN NaN NaN NaN NaN \n",
  1712. "3 27.0 1.0 1.0 0 2.0 NaN NaN NaN NaN NaN \n",
  1713. "4 16.0 6.0 2.0 2 1.0 NaN NaN NaN NaN NaN \n",
  1714. "5 5.0 0.0 1.0 0 1.0 NaN NaN NaN NaN NaN \n",
  1715. "6 2.0 0.0 0.0 1 0.0 NaN NaN NaN NaN NaN \n",
  1716. "7 34.0 11.0 6.0 13 1.0 NaN NaN NaN NaN NaN \n",
  1717. "8 1.0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1718. "9 11.0 1.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1719. "10 18.0 0.0 1.0 3 4.0 NaN NaN NaN NaN NaN \n",
  1720. "11 0.0 0.0 0.0 1 0.0 NaN NaN NaN NaN NaN \n",
  1721. "12 1.0 2.0 0.0 2 0.0 NaN NaN NaN NaN NaN \n",
  1722. "13 5.0 2.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1723. "14 21.0 4.0 0.0 2 2.0 NaN NaN NaN NaN NaN \n",
  1724. "15 23.0 4.0 4.0 9 2.0 NaN NaN NaN NaN NaN \n",
  1725. "16 0.0 0.0 0.0 0 3.0 NaN NaN NaN NaN NaN \n",
  1726. "17 0.0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1727. "18 8.0 3.0 1.0 4 2.0 NaN NaN NaN NaN NaN \n",
  1728. "19 0.0 0.0 0.0 1 0.0 NaN NaN NaN NaN NaN \n",
  1729. "20 13.0 1.0 0.0 3 2.0 NaN NaN NaN NaN NaN \n",
  1730. "21 24.0 6.0 0.0 4 4.0 NaN NaN NaN NaN NaN \n",
  1731. "22 21.0 4.0 0.0 7 2.0 NaN NaN NaN NaN NaN \n",
  1732. "23 0.0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1733. "24 14.0 0.0 0.0 1 1.0 NaN NaN NaN NaN NaN \n",
  1734. "25 10.0 5.0 0.0 2 1.0 NaN NaN NaN NaN NaN \n",
  1735. "26 18.0 2.0 1.0 8 3.0 NaN NaN NaN NaN NaN \n",
  1736. "27 16.0 12.0 1.0 8 2.0 NaN NaN NaN NaN NaN \n",
  1737. "28 2.0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  1738. "29 26.0 6.0 3.0 3 0.0 NaN NaN NaN NaN NaN \n",
  1739. "... ... ... ... .. ... ... ... ... ... ... \n",
  1740. "102786 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1741. "102787 30.0 4.0 1.0 21 53.0 2.0 0.0 4.0 0.0 1.0 \n",
  1742. "102788 23.0 7.0 0.0 34 52.0 2.0 9.0 0.0 5.0 3.0 \n",
  1743. "102789 2.0 0.0 0.0 1 9.0 0.0 0.0 2.0 0.0 0.0 \n",
  1744. "102790 0.0 0.0 0.0 0 2.0 0.0 0.0 0.0 0.0 0.0 \n",
  1745. "102791 1.0 0.0 0.0 1 5.0 0.0 0.0 0.0 0.0 0.0 \n",
  1746. "102792 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1747. "102793 1.0 0.0 0.0 1 6.0 0.0 0.0 0.0 0.0 1.0 \n",
  1748. "102794 14.0 3.0 2.0 26 55.0 0.0 0.0 0.0 0.0 0.0 \n",
  1749. "102795 0.0 0.0 0.0 0 2.0 0.0 0.0 1.0 0.0 0.0 \n",
  1750. "102796 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1751. "102797 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1752. "102798 0.0 0.0 0.0 0 3.0 0.0 0.0 0.0 0.0 0.0 \n",
  1753. "102799 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1754. "102800 98.0 9.0 4.0 72 138.0 4.0 4.0 0.0 5.0 20.0 \n",
  1755. "102801 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1756. "102802 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1757. "102803 0.0 0.0 0.0 0 2.0 0.0 0.0 0.0 0.0 0.0 \n",
  1758. "102804 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1759. "102805 24.0 4.0 2.0 21 50.0 0.0 3.0 0.0 0.0 4.0 \n",
  1760. "102806 0.0 1.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1761. "102807 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1762. "102808 0.0 0.0 0.0 0 2.0 0.0 0.0 0.0 0.0 0.0 \n",
  1763. "102809 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1764. "102810 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1765. "102811 0.0 0.0 0.0 0 2.0 0.0 0.0 1.0 0.0 0.0 \n",
  1766. "102812 46.0 4.0 1.0 29 104.0 1.0 5.0 0.0 6.0 12.0 \n",
  1767. "102813 76.0 6.0 4.0 96 82.0 6.0 4.0 4.0 4.0 17.0 \n",
  1768. "102814 31.0 0.0 0.0 21 65.0 0.0 6.0 0.0 1.0 0.0 \n",
  1769. "102815 0.0 0.0 0.0 0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  1770. "\n",
  1771. "[102816 rows x 22 columns]"
  1772. ]
  1773. },
  1774. "execution_count": 3,
  1775. "metadata": {},
  1776. "output_type": "execute_result"
  1777. }
  1778. ],
  1779. "source": [
  1780. "df"
  1781. ]
  1782. },
  1783. {
  1784. "cell_type": "markdown",
  1785. "metadata": {},
  1786. "source": [
  1787. "We will soon learn that Pandas, supports some typical \"Pythonic\" use cases for accesing data. The first we will encounter is with `len()`. We can get the size of this dataset (in rows) with the standard Python `len()` function, which will return exactly what we expect."
  1788. ]
  1789. },
  1790. {
  1791. "cell_type": "code",
  1792. "execution_count": 4,
  1793. "metadata": {},
  1794. "outputs": [
  1795. {
  1796. "data": {
  1797. "text/plain": [
  1798. "102816"
  1799. ]
  1800. },
  1801. "execution_count": 4,
  1802. "metadata": {},
  1803. "output_type": "execute_result"
  1804. }
  1805. ],
  1806. "source": [
  1807. "len(df)"
  1808. ]
  1809. },
  1810. {
  1811. "cell_type": "markdown",
  1812. "metadata": {},
  1813. "source": [
  1814. "Every DataFrame will have a `columns` attribute, which contains the _column index_ for our dataset. Thus, getting the length of that attribute returns, again, what we expect."
  1815. ]
  1816. },
  1817. {
  1818. "cell_type": "code",
  1819. "execution_count": 5,
  1820. "metadata": {},
  1821. "outputs": [
  1822. {
  1823. "data": {
  1824. "text/plain": [
  1825. "Index(['playerID', 'yearID', 'stint', 'teamID', 'lgID', 'G', 'AB', 'R', 'H',\n",
  1826. " '2B', '3B', 'HR', 'RBI', 'SB', 'CS', 'BB', 'SO', 'IBB', 'HBP', 'SH',\n",
  1827. " 'SF', 'GIDP'],\n",
  1828. " dtype='object')"
  1829. ]
  1830. },
  1831. "execution_count": 5,
  1832. "metadata": {},
  1833. "output_type": "execute_result"
  1834. }
  1835. ],
  1836. "source": [
  1837. "df.columns"
  1838. ]
  1839. },
  1840. {
  1841. "cell_type": "code",
  1842. "execution_count": 6,
  1843. "metadata": {},
  1844. "outputs": [
  1845. {
  1846. "data": {
  1847. "text/plain": [
  1848. "22"
  1849. ]
  1850. },
  1851. "execution_count": 6,
  1852. "metadata": {},
  1853. "output_type": "execute_result"
  1854. }
  1855. ],
  1856. "source": [
  1857. "len(df.columns)"
  1858. ]
  1859. },
  1860. {
  1861. "cell_type": "markdown",
  1862. "metadata": {},
  1863. "source": [
  1864. "If we want both column and row counts [`DataFrame.shape`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shape.html#pandas.DataFrame.shape) will return the tuple to do this:"
  1865. ]
  1866. },
  1867. {
  1868. "cell_type": "code",
  1869. "execution_count": 7,
  1870. "metadata": {},
  1871. "outputs": [
  1872. {
  1873. "data": {
  1874. "text/plain": [
  1875. "(102816, 22)"
  1876. ]
  1877. },
  1878. "execution_count": 7,
  1879. "metadata": {},
  1880. "output_type": "execute_result"
  1881. }
  1882. ],
  1883. "source": [
  1884. "df.shape"
  1885. ]
  1886. },
  1887. {
  1888. "cell_type": "markdown",
  1889. "metadata": {},
  1890. "source": [
  1891. "Which returns what we expect (yet again).\n",
  1892. "\n",
  1893. "Much like Python slicing of lists, if we want to the first _n_ rows of data, we can use the shorthand:"
  1894. ]
  1895. },
  1896. {
  1897. "cell_type": "code",
  1898. "execution_count": 8,
  1899. "metadata": {},
  1900. "outputs": [
  1901. {
  1902. "data": {
  1903. "text/html": [
  1904. "<div>\n",
  1905. "<style>\n",
  1906. " .dataframe thead tr:only-child th {\n",
  1907. " text-align: right;\n",
  1908. " }\n",
  1909. "\n",
  1910. " .dataframe thead th {\n",
  1911. " text-align: left;\n",
  1912. " }\n",
  1913. "\n",
  1914. " .dataframe tbody tr th {\n",
  1915. " vertical-align: top;\n",
  1916. " }\n",
  1917. "</style>\n",
  1918. "<table border=\"1\" class=\"dataframe\">\n",
  1919. " <thead>\n",
  1920. " <tr style=\"text-align: right;\">\n",
  1921. " <th></th>\n",
  1922. " <th>playerID</th>\n",
  1923. " <th>yearID</th>\n",
  1924. " <th>stint</th>\n",
  1925. " <th>teamID</th>\n",
  1926. " <th>lgID</th>\n",
  1927. " <th>G</th>\n",
  1928. " <th>AB</th>\n",
  1929. " <th>R</th>\n",
  1930. " <th>H</th>\n",
  1931. " <th>2B</th>\n",
  1932. " <th>...</th>\n",
  1933. " <th>RBI</th>\n",
  1934. " <th>SB</th>\n",
  1935. " <th>CS</th>\n",
  1936. " <th>BB</th>\n",
  1937. " <th>SO</th>\n",
  1938. " <th>IBB</th>\n",
  1939. " <th>HBP</th>\n",
  1940. " <th>SH</th>\n",
  1941. " <th>SF</th>\n",
  1942. " <th>GIDP</th>\n",
  1943. " </tr>\n",
  1944. " </thead>\n",
  1945. " <tbody>\n",
  1946. " <tr>\n",
  1947. " <th>0</th>\n",
  1948. " <td>abercda01</td>\n",
  1949. " <td>1871</td>\n",
  1950. " <td>1</td>\n",
  1951. " <td>TRO</td>\n",
  1952. " <td>NaN</td>\n",
  1953. " <td>1</td>\n",
  1954. " <td>4</td>\n",
  1955. " <td>0</td>\n",
  1956. " <td>0</td>\n",
  1957. " <td>0</td>\n",
  1958. " <td>...</td>\n",
  1959. " <td>0.0</td>\n",
  1960. " <td>0.0</td>\n",
  1961. " <td>0.0</td>\n",
  1962. " <td>0</td>\n",
  1963. " <td>0.0</td>\n",
  1964. " <td>NaN</td>\n",
  1965. " <td>NaN</td>\n",
  1966. " <td>NaN</td>\n",
  1967. " <td>NaN</td>\n",
  1968. " <td>NaN</td>\n",
  1969. " </tr>\n",
  1970. " <tr>\n",
  1971. " <th>1</th>\n",
  1972. " <td>addybo01</td>\n",
  1973. " <td>1871</td>\n",
  1974. " <td>1</td>\n",
  1975. " <td>RC1</td>\n",
  1976. " <td>NaN</td>\n",
  1977. " <td>25</td>\n",
  1978. " <td>118</td>\n",
  1979. " <td>30</td>\n",
  1980. " <td>32</td>\n",
  1981. " <td>6</td>\n",
  1982. " <td>...</td>\n",
  1983. " <td>13.0</td>\n",
  1984. " <td>8.0</td>\n",
  1985. " <td>1.0</td>\n",
  1986. " <td>4</td>\n",
  1987. " <td>0.0</td>\n",
  1988. " <td>NaN</td>\n",
  1989. " <td>NaN</td>\n",
  1990. " <td>NaN</td>\n",
  1991. " <td>NaN</td>\n",
  1992. " <td>NaN</td>\n",
  1993. " </tr>\n",
  1994. " <tr>\n",
  1995. " <th>2</th>\n",
  1996. " <td>allisar01</td>\n",
  1997. " <td>1871</td>\n",
  1998. " <td>1</td>\n",
  1999. " <td>CL1</td>\n",
  2000. " <td>NaN</td>\n",
  2001. " <td>29</td>\n",
  2002. " <td>137</td>\n",
  2003. " <td>28</td>\n",
  2004. " <td>40</td>\n",
  2005. " <td>4</td>\n",
  2006. " <td>...</td>\n",
  2007. " <td>19.0</td>\n",
  2008. " <td>3.0</td>\n",
  2009. " <td>1.0</td>\n",
  2010. " <td>2</td>\n",
  2011. " <td>5.0</td>\n",
  2012. " <td>NaN</td>\n",
  2013. " <td>NaN</td>\n",
  2014. " <td>NaN</td>\n",
  2015. " <td>NaN</td>\n",
  2016. " <td>NaN</td>\n",
  2017. " </tr>\n",
  2018. " <tr>\n",
  2019. " <th>3</th>\n",
  2020. " <td>allisdo01</td>\n",
  2021. " <td>1871</td>\n",
  2022. " <td>1</td>\n",
  2023. " <td>WS3</td>\n",
  2024. " <td>NaN</td>\n",
  2025. " <td>27</td>\n",
  2026. " <td>133</td>\n",
  2027. " <td>28</td>\n",
  2028. " <td>44</td>\n",
  2029. " <td>10</td>\n",
  2030. " <td>...</td>\n",
  2031. " <td>27.0</td>\n",
  2032. " <td>1.0</td>\n",
  2033. " <td>1.0</td>\n",
  2034. " <td>0</td>\n",
  2035. " <td>2.0</td>\n",
  2036. " <td>NaN</td>\n",
  2037. " <td>NaN</td>\n",
  2038. " <td>NaN</td>\n",
  2039. " <td>NaN</td>\n",
  2040. " <td>NaN</td>\n",
  2041. " </tr>\n",
  2042. " <tr>\n",
  2043. " <th>4</th>\n",
  2044. " <td>ansonca01</td>\n",
  2045. " <td>1871</td>\n",
  2046. " <td>1</td>\n",
  2047. " <td>RC1</td>\n",
  2048. " <td>NaN</td>\n",
  2049. " <td>25</td>\n",
  2050. " <td>120</td>\n",
  2051. " <td>29</td>\n",
  2052. " <td>39</td>\n",
  2053. " <td>11</td>\n",
  2054. " <td>...</td>\n",
  2055. " <td>16.0</td>\n",
  2056. " <td>6.0</td>\n",
  2057. " <td>2.0</td>\n",
  2058. " <td>2</td>\n",
  2059. " <td>1.0</td>\n",
  2060. " <td>NaN</td>\n",
  2061. " <td>NaN</td>\n",
  2062. " <td>NaN</td>\n",
  2063. " <td>NaN</td>\n",
  2064. " <td>NaN</td>\n",
  2065. " </tr>\n",
  2066. " <tr>\n",
  2067. " <th>5</th>\n",
  2068. " <td>armstbo01</td>\n",
  2069. " <td>1871</td>\n",
  2070. " <td>1</td>\n",
  2071. " <td>FW1</td>\n",
  2072. " <td>NaN</td>\n",
  2073. " <td>12</td>\n",
  2074. " <td>49</td>\n",
  2075. " <td>9</td>\n",
  2076. " <td>11</td>\n",
  2077. " <td>2</td>\n",
  2078. " <td>...</td>\n",
  2079. " <td>5.0</td>\n",
  2080. " <td>0.0</td>\n",
  2081. " <td>1.0</td>\n",
  2082. " <td>0</td>\n",
  2083. " <td>1.0</td>\n",
  2084. " <td>NaN</td>\n",
  2085. " <td>NaN</td>\n",
  2086. " <td>NaN</td>\n",
  2087. " <td>NaN</td>\n",
  2088. " <td>NaN</td>\n",
  2089. " </tr>\n",
  2090. " <tr>\n",
  2091. " <th>6</th>\n",
  2092. " <td>barkeal01</td>\n",
  2093. " <td>1871</td>\n",
  2094. " <td>1</td>\n",
  2095. " <td>RC1</td>\n",
  2096. " <td>NaN</td>\n",
  2097. " <td>1</td>\n",
  2098. " <td>4</td>\n",
  2099. " <td>0</td>\n",
  2100. " <td>1</td>\n",
  2101. " <td>0</td>\n",
  2102. " <td>...</td>\n",
  2103. " <td>2.0</td>\n",
  2104. " <td>0.0</td>\n",
  2105. " <td>0.0</td>\n",
  2106. " <td>1</td>\n",
  2107. " <td>0.0</td>\n",
  2108. " <td>NaN</td>\n",
  2109. " <td>NaN</td>\n",
  2110. " <td>NaN</td>\n",
  2111. " <td>NaN</td>\n",
  2112. " <td>NaN</td>\n",
  2113. " </tr>\n",
  2114. " <tr>\n",
  2115. " <th>7</th>\n",
  2116. " <td>barnero01</td>\n",
  2117. " <td>1871</td>\n",
  2118. " <td>1</td>\n",
  2119. " <td>BS1</td>\n",
  2120. " <td>NaN</td>\n",
  2121. " <td>31</td>\n",
  2122. " <td>157</td>\n",
  2123. " <td>66</td>\n",
  2124. " <td>63</td>\n",
  2125. " <td>10</td>\n",
  2126. " <td>...</td>\n",
  2127. " <td>34.0</td>\n",
  2128. " <td>11.0</td>\n",
  2129. " <td>6.0</td>\n",
  2130. " <td>13</td>\n",
  2131. " <td>1.0</td>\n",
  2132. " <td>NaN</td>\n",
  2133. " <td>NaN</td>\n",
  2134. " <td>NaN</td>\n",
  2135. " <td>NaN</td>\n",
  2136. " <td>NaN</td>\n",
  2137. " </tr>\n",
  2138. " <tr>\n",
  2139. " <th>8</th>\n",
  2140. " <td>barrebi01</td>\n",
  2141. " <td>1871</td>\n",
  2142. " <td>1</td>\n",
  2143. " <td>FW1</td>\n",
  2144. " <td>NaN</td>\n",
  2145. " <td>1</td>\n",
  2146. " <td>5</td>\n",
  2147. " <td>1</td>\n",
  2148. " <td>1</td>\n",
  2149. " <td>1</td>\n",
  2150. " <td>...</td>\n",
  2151. " <td>1.0</td>\n",
  2152. " <td>0.0</td>\n",
  2153. " <td>0.0</td>\n",
  2154. " <td>0</td>\n",
  2155. " <td>0.0</td>\n",
  2156. " <td>NaN</td>\n",
  2157. " <td>NaN</td>\n",
  2158. " <td>NaN</td>\n",
  2159. " <td>NaN</td>\n",
  2160. " <td>NaN</td>\n",
  2161. " </tr>\n",
  2162. " <tr>\n",
  2163. " <th>9</th>\n",
  2164. " <td>barrofr01</td>\n",
  2165. " <td>1871</td>\n",
  2166. " <td>1</td>\n",
  2167. " <td>BS1</td>\n",
  2168. " <td>NaN</td>\n",
  2169. " <td>18</td>\n",
  2170. " <td>86</td>\n",
  2171. " <td>13</td>\n",
  2172. " <td>13</td>\n",
  2173. " <td>2</td>\n",
  2174. " <td>...</td>\n",
  2175. " <td>11.0</td>\n",
  2176. " <td>1.0</td>\n",
  2177. " <td>0.0</td>\n",
  2178. " <td>0</td>\n",
  2179. " <td>0.0</td>\n",
  2180. " <td>NaN</td>\n",
  2181. " <td>NaN</td>\n",
  2182. " <td>NaN</td>\n",
  2183. " <td>NaN</td>\n",
  2184. " <td>NaN</td>\n",
  2185. " </tr>\n",
  2186. " </tbody>\n",
  2187. "</table>\n",
  2188. "<p>10 rows × 22 columns</p>\n",
  2189. "</div>"
  2190. ],
  2191. "text/plain": [
  2192. " playerID yearID stint teamID lgID G AB R H 2B ... RBI \\\n",
  2193. "0 abercda01 1871 1 TRO NaN 1 4 0 0 0 ... 0.0 \n",
  2194. "1 addybo01 1871 1 RC1 NaN 25 118 30 32 6 ... 13.0 \n",
  2195. "2 allisar01 1871 1 CL1 NaN 29 137 28 40 4 ... 19.0 \n",
  2196. "3 allisdo01 1871 1 WS3 NaN 27 133 28 44 10 ... 27.0 \n",
  2197. "4 ansonca01 1871 1 RC1 NaN 25 120 29 39 11 ... 16.0 \n",
  2198. "5 armstbo01 1871 1 FW1 NaN 12 49 9 11 2 ... 5.0 \n",
  2199. "6 barkeal01 1871 1 RC1 NaN 1 4 0 1 0 ... 2.0 \n",
  2200. "7 barnero01 1871 1 BS1 NaN 31 157 66 63 10 ... 34.0 \n",
  2201. "8 barrebi01 1871 1 FW1 NaN 1 5 1 1 1 ... 1.0 \n",
  2202. "9 barrofr01 1871 1 BS1 NaN 18 86 13 13 2 ... 11.0 \n",
  2203. "\n",
  2204. " SB CS BB SO IBB HBP SH SF GIDP \n",
  2205. "0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  2206. "1 8.0 1.0 4 0.0 NaN NaN NaN NaN NaN \n",
  2207. "2 3.0 1.0 2 5.0 NaN NaN NaN NaN NaN \n",
  2208. "3 1.0 1.0 0 2.0 NaN NaN NaN NaN NaN \n",
  2209. "4 6.0 2.0 2 1.0 NaN NaN NaN NaN NaN \n",
  2210. "5 0.0 1.0 0 1.0 NaN NaN NaN NaN NaN \n",
  2211. "6 0.0 0.0 1 0.0 NaN NaN NaN NaN NaN \n",
  2212. "7 11.0 6.0 13 1.0 NaN NaN NaN NaN NaN \n",
  2213. "8 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  2214. "9 1.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  2215. "\n",
  2216. "[10 rows x 22 columns]"
  2217. ]
  2218. },
  2219. "execution_count": 8,
  2220. "metadata": {},
  2221. "output_type": "execute_result"
  2222. }
  2223. ],
  2224. "source": [
  2225. "df[:10]"
  2226. ]
  2227. },
  2228. {
  2229. "cell_type": "markdown",
  2230. "metadata": {},
  2231. "source": [
  2232. "Or just like slicing a list, we can do more complex slicing:"
  2233. ]
  2234. },
  2235. {
  2236. "cell_type": "code",
  2237. "execution_count": 9,
  2238. "metadata": {},
  2239. "outputs": [
  2240. {
  2241. "data": {
  2242. "text/html": [
  2243. "<div>\n",
  2244. "<style>\n",
  2245. " .dataframe thead tr:only-child th {\n",
  2246. " text-align: right;\n",
  2247. " }\n",
  2248. "\n",
  2249. " .dataframe thead th {\n",
  2250. " text-align: left;\n",
  2251. " }\n",
  2252. "\n",
  2253. " .dataframe tbody tr th {\n",
  2254. " vertical-align: top;\n",
  2255. " }\n",
  2256. "</style>\n",
  2257. "<table border=\"1\" class=\"dataframe\">\n",
  2258. " <thead>\n",
  2259. " <tr style=\"text-align: right;\">\n",
  2260. " <th></th>\n",
  2261. " <th>playerID</th>\n",
  2262. " <th>yearID</th>\n",
  2263. " <th>stint</th>\n",
  2264. " <th>teamID</th>\n",
  2265. " <th>lgID</th>\n",
  2266. " <th>G</th>\n",
  2267. " <th>AB</th>\n",
  2268. " <th>R</th>\n",
  2269. " <th>H</th>\n",
  2270. " <th>2B</th>\n",
  2271. " <th>...</th>\n",
  2272. " <th>RBI</th>\n",
  2273. " <th>SB</th>\n",
  2274. " <th>CS</th>\n",
  2275. " <th>BB</th>\n",
  2276. " <th>SO</th>\n",
  2277. " <th>IBB</th>\n",
  2278. " <th>HBP</th>\n",
  2279. " <th>SH</th>\n",
  2280. " <th>SF</th>\n",
  2281. " <th>GIDP</th>\n",
  2282. " </tr>\n",
  2283. " </thead>\n",
  2284. " <tbody>\n",
  2285. " <tr>\n",
  2286. " <th>0</th>\n",
  2287. " <td>abercda01</td>\n",
  2288. " <td>1871</td>\n",
  2289. " <td>1</td>\n",
  2290. " <td>TRO</td>\n",
  2291. " <td>NaN</td>\n",
  2292. " <td>1</td>\n",
  2293. " <td>4</td>\n",
  2294. " <td>0</td>\n",
  2295. " <td>0</td>\n",
  2296. " <td>0</td>\n",
  2297. " <td>...</td>\n",
  2298. " <td>0.0</td>\n",
  2299. " <td>0.0</td>\n",
  2300. " <td>0.0</td>\n",
  2301. " <td>0</td>\n",
  2302. " <td>0.0</td>\n",
  2303. " <td>NaN</td>\n",
  2304. " <td>NaN</td>\n",
  2305. " <td>NaN</td>\n",
  2306. " <td>NaN</td>\n",
  2307. " <td>NaN</td>\n",
  2308. " </tr>\n",
  2309. " <tr>\n",
  2310. " <th>5</th>\n",
  2311. " <td>armstbo01</td>\n",
  2312. " <td>1871</td>\n",
  2313. " <td>1</td>\n",
  2314. " <td>FW1</td>\n",
  2315. " <td>NaN</td>\n",
  2316. " <td>12</td>\n",
  2317. " <td>49</td>\n",
  2318. " <td>9</td>\n",
  2319. " <td>11</td>\n",
  2320. " <td>2</td>\n",
  2321. " <td>...</td>\n",
  2322. " <td>5.0</td>\n",
  2323. " <td>0.0</td>\n",
  2324. " <td>1.0</td>\n",
  2325. " <td>0</td>\n",
  2326. " <td>1.0</td>\n",
  2327. " <td>NaN</td>\n",
  2328. " <td>NaN</td>\n",
  2329. " <td>NaN</td>\n",
  2330. " <td>NaN</td>\n",
  2331. " <td>NaN</td>\n",
  2332. " </tr>\n",
  2333. " <tr>\n",
  2334. " <th>10</th>\n",
  2335. " <td>bassjo01</td>\n",
  2336. " <td>1871</td>\n",
  2337. " <td>1</td>\n",
  2338. " <td>CL1</td>\n",
  2339. " <td>NaN</td>\n",
  2340. " <td>22</td>\n",
  2341. " <td>89</td>\n",
  2342. " <td>18</td>\n",
  2343. " <td>27</td>\n",
  2344. " <td>1</td>\n",
  2345. " <td>...</td>\n",
  2346. " <td>18.0</td>\n",
  2347. " <td>0.0</td>\n",
  2348. " <td>1.0</td>\n",
  2349. " <td>3</td>\n",
  2350. " <td>4.0</td>\n",
  2351. " <td>NaN</td>\n",
  2352. " <td>NaN</td>\n",
  2353. " <td>NaN</td>\n",
  2354. " <td>NaN</td>\n",
  2355. " <td>NaN</td>\n",
  2356. " </tr>\n",
  2357. " <tr>\n",
  2358. " <th>15</th>\n",
  2359. " <td>bellast01</td>\n",
  2360. " <td>1871</td>\n",
  2361. " <td>1</td>\n",
  2362. " <td>TRO</td>\n",
  2363. " <td>NaN</td>\n",
  2364. " <td>29</td>\n",
  2365. " <td>128</td>\n",
  2366. " <td>26</td>\n",
  2367. " <td>32</td>\n",
  2368. " <td>3</td>\n",
  2369. " <td>...</td>\n",
  2370. " <td>23.0</td>\n",
  2371. " <td>4.0</td>\n",
  2372. " <td>4.0</td>\n",
  2373. " <td>9</td>\n",
  2374. " <td>2.0</td>\n",
  2375. " <td>NaN</td>\n",
  2376. " <td>NaN</td>\n",
  2377. " <td>NaN</td>\n",
  2378. " <td>NaN</td>\n",
  2379. " <td>NaN</td>\n",
  2380. " </tr>\n",
  2381. " <tr>\n",
  2382. " <th>20</th>\n",
  2383. " <td>birdge01</td>\n",
  2384. " <td>1871</td>\n",
  2385. " <td>1</td>\n",
  2386. " <td>RC1</td>\n",
  2387. " <td>NaN</td>\n",
  2388. " <td>25</td>\n",
  2389. " <td>106</td>\n",
  2390. " <td>19</td>\n",
  2391. " <td>28</td>\n",
  2392. " <td>2</td>\n",
  2393. " <td>...</td>\n",
  2394. " <td>13.0</td>\n",
  2395. " <td>1.0</td>\n",
  2396. " <td>0.0</td>\n",
  2397. " <td>3</td>\n",
  2398. " <td>2.0</td>\n",
  2399. " <td>NaN</td>\n",
  2400. " <td>NaN</td>\n",
  2401. " <td>NaN</td>\n",
  2402. " <td>NaN</td>\n",
  2403. " <td>NaN</td>\n",
  2404. " </tr>\n",
  2405. " <tr>\n",
  2406. " <th>25</th>\n",
  2407. " <td>careyto01</td>\n",
  2408. " <td>1871</td>\n",
  2409. " <td>1</td>\n",
  2410. " <td>FW1</td>\n",
  2411. " <td>NaN</td>\n",
  2412. " <td>19</td>\n",
  2413. " <td>87</td>\n",
  2414. " <td>16</td>\n",
  2415. " <td>20</td>\n",
  2416. " <td>2</td>\n",
  2417. " <td>...</td>\n",
  2418. " <td>10.0</td>\n",
  2419. " <td>5.0</td>\n",
  2420. " <td>0.0</td>\n",
  2421. " <td>2</td>\n",
  2422. " <td>1.0</td>\n",
  2423. " <td>NaN</td>\n",
  2424. " <td>NaN</td>\n",
  2425. " <td>NaN</td>\n",
  2426. " <td>NaN</td>\n",
  2427. " <td>NaN</td>\n",
  2428. " </tr>\n",
  2429. " <tr>\n",
  2430. " <th>30</th>\n",
  2431. " <td>cuthbne01</td>\n",
  2432. " <td>1871</td>\n",
  2433. " <td>1</td>\n",
  2434. " <td>PH1</td>\n",
  2435. " <td>NaN</td>\n",
  2436. " <td>28</td>\n",
  2437. " <td>150</td>\n",
  2438. " <td>47</td>\n",
  2439. " <td>37</td>\n",
  2440. " <td>7</td>\n",
  2441. " <td>...</td>\n",
  2442. " <td>30.0</td>\n",
  2443. " <td>16.0</td>\n",
  2444. " <td>2.0</td>\n",
  2445. " <td>10</td>\n",
  2446. " <td>2.0</td>\n",
  2447. " <td>NaN</td>\n",
  2448. " <td>NaN</td>\n",
  2449. " <td>NaN</td>\n",
  2450. " <td>NaN</td>\n",
  2451. " <td>NaN</td>\n",
  2452. " </tr>\n",
  2453. " <tr>\n",
  2454. " <th>35</th>\n",
  2455. " <td>ewellge01</td>\n",
  2456. " <td>1871</td>\n",
  2457. " <td>1</td>\n",
  2458. " <td>CL1</td>\n",
  2459. " <td>NaN</td>\n",
  2460. " <td>1</td>\n",
  2461. " <td>3</td>\n",
  2462. " <td>0</td>\n",
  2463. " <td>0</td>\n",
  2464. " <td>0</td>\n",
  2465. " <td>...</td>\n",
  2466. " <td>0.0</td>\n",
  2467. " <td>0.0</td>\n",
  2468. " <td>0.0</td>\n",
  2469. " <td>0</td>\n",
  2470. " <td>0.0</td>\n",
  2471. " <td>NaN</td>\n",
  2472. " <td>NaN</td>\n",
  2473. " <td>NaN</td>\n",
  2474. " <td>NaN</td>\n",
  2475. " <td>NaN</td>\n",
  2476. " </tr>\n",
  2477. " <tr>\n",
  2478. " <th>40</th>\n",
  2479. " <td>flowedi01</td>\n",
  2480. " <td>1871</td>\n",
  2481. " <td>1</td>\n",
  2482. " <td>TRO</td>\n",
  2483. " <td>NaN</td>\n",
  2484. " <td>21</td>\n",
  2485. " <td>105</td>\n",
  2486. " <td>39</td>\n",
  2487. " <td>33</td>\n",
  2488. " <td>5</td>\n",
  2489. " <td>...</td>\n",
  2490. " <td>18.0</td>\n",
  2491. " <td>8.0</td>\n",
  2492. " <td>2.0</td>\n",
  2493. " <td>4</td>\n",
  2494. " <td>0.0</td>\n",
  2495. " <td>NaN</td>\n",
  2496. " <td>NaN</td>\n",
  2497. " <td>NaN</td>\n",
  2498. " <td>NaN</td>\n",
  2499. " <td>NaN</td>\n",
  2500. " </tr>\n",
  2501. " <tr>\n",
  2502. " <th>45</th>\n",
  2503. " <td>fulmech01</td>\n",
  2504. " <td>1871</td>\n",
  2505. " <td>1</td>\n",
  2506. " <td>RC1</td>\n",
  2507. " <td>NaN</td>\n",
  2508. " <td>16</td>\n",
  2509. " <td>63</td>\n",
  2510. " <td>11</td>\n",
  2511. " <td>17</td>\n",
  2512. " <td>1</td>\n",
  2513. " <td>...</td>\n",
  2514. " <td>3.0</td>\n",
  2515. " <td>0.0</td>\n",
  2516. " <td>0.0</td>\n",
  2517. " <td>5</td>\n",
  2518. " <td>1.0</td>\n",
  2519. " <td>NaN</td>\n",
  2520. " <td>NaN</td>\n",
  2521. " <td>NaN</td>\n",
  2522. " <td>NaN</td>\n",
  2523. " <td>NaN</td>\n",
  2524. " </tr>\n",
  2525. " </tbody>\n",
  2526. "</table>\n",
  2527. "<p>10 rows × 22 columns</p>\n",
  2528. "</div>"
  2529. ],
  2530. "text/plain": [
  2531. " playerID yearID stint teamID lgID G AB R H 2B ... RBI \\\n",
  2532. "0 abercda01 1871 1 TRO NaN 1 4 0 0 0 ... 0.0 \n",
  2533. "5 armstbo01 1871 1 FW1 NaN 12 49 9 11 2 ... 5.0 \n",
  2534. "10 bassjo01 1871 1 CL1 NaN 22 89 18 27 1 ... 18.0 \n",
  2535. "15 bellast01 1871 1 TRO NaN 29 128 26 32 3 ... 23.0 \n",
  2536. "20 birdge01 1871 1 RC1 NaN 25 106 19 28 2 ... 13.0 \n",
  2537. "25 careyto01 1871 1 FW1 NaN 19 87 16 20 2 ... 10.0 \n",
  2538. "30 cuthbne01 1871 1 PH1 NaN 28 150 47 37 7 ... 30.0 \n",
  2539. "35 ewellge01 1871 1 CL1 NaN 1 3 0 0 0 ... 0.0 \n",
  2540. "40 flowedi01 1871 1 TRO NaN 21 105 39 33 5 ... 18.0 \n",
  2541. "45 fulmech01 1871 1 RC1 NaN 16 63 11 17 1 ... 3.0 \n",
  2542. "\n",
  2543. " SB CS BB SO IBB HBP SH SF GIDP \n",
  2544. "0 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  2545. "5 0.0 1.0 0 1.0 NaN NaN NaN NaN NaN \n",
  2546. "10 0.0 1.0 3 4.0 NaN NaN NaN NaN NaN \n",
  2547. "15 4.0 4.0 9 2.0 NaN NaN NaN NaN NaN \n",
  2548. "20 1.0 0.0 3 2.0 NaN NaN NaN NaN NaN \n",
  2549. "25 5.0 0.0 2 1.0 NaN NaN NaN NaN NaN \n",
  2550. "30 16.0 2.0 10 2.0 NaN NaN NaN NaN NaN \n",
  2551. "35 0.0 0.0 0 0.0 NaN NaN NaN NaN NaN \n",
  2552. "40 8.0 2.0 4 0.0 NaN NaN NaN NaN NaN \n",
  2553. "45 0.0 0.0 5 1.0 NaN NaN NaN NaN NaN \n",
  2554. "\n",
  2555. "[10 rows x 22 columns]"
  2556. ]
  2557. },
  2558. "execution_count": 9,
  2559. "metadata": {},
  2560. "output_type": "execute_result"
  2561. }
  2562. ],
  2563. "source": [
  2564. "df[:50:5]"
  2565. ]
  2566. },
  2567. {
  2568. "cell_type": "markdown",
  2569. "metadata": {},
  2570. "source": [
  2571. "### Accessing column data by label\n",
  2572. "\n",
  2573. "One of the nice things about Pandas is that we can reference the columns of data by their names (or labels). For example, we have a `yearID` label, `teamID` label, `G` label for game counts, and so on. For our dataset to learn what the labels are in detail see the documentation for the provided links."
  2574. ]
  2575. },
  2576. {
  2577. "cell_type": "code",
  2578. "execution_count": 10,
  2579. "metadata": {},
  2580. "outputs": [
  2581. {
  2582. "data": {
  2583. "text/plain": [
  2584. "0 1871\n",
  2585. "1 1871\n",
  2586. "2 1871\n",
  2587. "3 1871\n",
  2588. "4 1871\n",
  2589. "5 1871\n",
  2590. "6 1871\n",
  2591. "7 1871\n",
  2592. "8 1871\n",
  2593. "9 1871\n",
  2594. "Name: yearID, dtype: int64"
  2595. ]
  2596. },
  2597. "execution_count": 10,
  2598. "metadata": {},
  2599. "output_type": "execute_result"
  2600. }
  2601. ],
  2602. "source": [
  2603. "df.yearID[:10]"
  2604. ]
  2605. },
  2606. {
  2607. "cell_type": "code",
  2608. "execution_count": 11,
  2609. "metadata": {},
  2610. "outputs": [
  2611. {
  2612. "data": {
  2613. "text/plain": [
  2614. "102806 6\n",
  2615. "102807 8\n",
  2616. "102808 8\n",
  2617. "102809 36\n",
  2618. "102810 33\n",
  2619. "102811 19\n",
  2620. "102812 115\n",
  2621. "102813 147\n",
  2622. "102814 55\n",
  2623. "102815 12\n",
  2624. "Name: G, dtype: int64"
  2625. ]
  2626. },
  2627. "execution_count": 11,
  2628. "metadata": {},
  2629. "output_type": "execute_result"
  2630. }
  2631. ],
  2632. "source": [
  2633. "df.G[-10:]"
  2634. ]
  2635. },
  2636. {
  2637. "cell_type": "markdown",
  2638. "metadata": {},
  2639. "source": [
  2640. "Let's say we want all the player data for the [Washington Nationals](https://www.mlb.com/nationals) from 2015 and 2016 where a player played in 100 or more games:"
  2641. ]
  2642. },
  2643. {
  2644. "cell_type": "code",
  2645. "execution_count": 12,
  2646. "metadata": {},
  2647. "outputs": [
  2648. {
  2649. "data": {
  2650. "text/html": [
  2651. "<div>\n",
  2652. "<style>\n",
  2653. " .dataframe thead tr:only-child th {\n",
  2654. " text-align: right;\n",
  2655. " }\n",
  2656. "\n",
  2657. " .dataframe thead th {\n",
  2658. " text-align: left;\n",
  2659. " }\n",
  2660. "\n",
  2661. " .dataframe tbody tr th {\n",
  2662. " vertical-align: top;\n",
  2663. " }\n",
  2664. "</style>\n",
  2665. "<table border=\"1\" class=\"dataframe\">\n",
  2666. " <thead>\n",
  2667. " <tr style=\"text-align: right;\">\n",
  2668. " <th></th>\n",
  2669. " <th>playerID</th>\n",
  2670. " <th>yearID</th>\n",
  2671. " <th>stint</th>\n",
  2672. " <th>teamID</th>\n",
  2673. " <th>lgID</th>\n",
  2674. " <th>G</th>\n",
  2675. " <th>AB</th>\n",
  2676. " <th>R</th>\n",
  2677. " <th>H</th>\n",
  2678. " <th>2B</th>\n",
  2679. " <th>...</th>\n",
  2680. " <th>RBI</th>\n",
  2681. " <th>SB</th>\n",
  2682. " <th>CS</th>\n",
  2683. " <th>BB</th>\n",
  2684. " <th>SO</th>\n",
  2685. " <th>IBB</th>\n",
  2686. " <th>HBP</th>\n",
  2687. " <th>SH</th>\n",
  2688. " <th>SF</th>\n",
  2689. " <th>GIDP</th>\n",
  2690. " </tr>\n",
  2691. " </thead>\n",
  2692. " <tbody>\n",
  2693. " <tr>\n",
  2694. " <th>100193</th>\n",
  2695. " <td>desmoia01</td>\n",
  2696. " <td>2015</td>\n",
  2697. " <td>1</td>\n",
  2698. " <td>WAS</td>\n",
  2699. " <td>NL</td>\n",
  2700. " <td>156</td>\n",
  2701. " <td>583</td>\n",
  2702. " <td>69</td>\n",
  2703. " <td>136</td>\n",
  2704. " <td>27</td>\n",
  2705. " <td>...</td>\n",
  2706. " <td>62.0</td>\n",
  2707. " <td>13.0</td>\n",
  2708. " <td>5.0</td>\n",
  2709. " <td>45</td>\n",
  2710. " <td>187.0</td>\n",
  2711. " <td>0.0</td>\n",
  2712. " <td>3.0</td>\n",
  2713. " <td>6.0</td>\n",
  2714. " <td>4.0</td>\n",
  2715. " <td>9.0</td>\n",
  2716. " </tr>\n",
  2717. " <tr>\n",
  2718. " <th>100250</th>\n",
  2719. " <td>escobyu01</td>\n",
  2720. " <td>2015</td>\n",
  2721. " <td>1</td>\n",
  2722. " <td>WAS</td>\n",
  2723. " <td>NL</td>\n",
  2724. " <td>139</td>\n",
  2725. " <td>535</td>\n",
  2726. " <td>75</td>\n",
  2727. " <td>168</td>\n",
  2728. " <td>25</td>\n",
  2729. " <td>...</td>\n",
  2730. " <td>56.0</td>\n",
  2731. " <td>2.0</td>\n",
  2732. " <td>2.0</td>\n",
  2733. " <td>45</td>\n",
  2734. " <td>70.0</td>\n",
  2735. " <td>0.0</td>\n",
  2736. " <td>8.0</td>\n",
  2737. " <td>1.0</td>\n",
  2738. " <td>2.0</td>\n",
  2739. " <td>24.0</td>\n",
  2740. " </tr>\n",
  2741. " <tr>\n",
  2742. " <th>100251</th>\n",
  2743. " <td>espinda01</td>\n",
  2744. " <td>2015</td>\n",
  2745. " <td>1</td>\n",
  2746. " <td>WAS</td>\n",
  2747. " <td>NL</td>\n",
  2748. " <td>118</td>\n",
  2749. " <td>367</td>\n",
  2750. " <td>59</td>\n",
  2751. " <td>88</td>\n",
  2752. " <td>21</td>\n",
  2753. " <td>...</td>\n",
  2754. " <td>37.0</td>\n",
  2755. " <td>5.0</td>\n",
  2756. " <td>2.0</td>\n",
  2757. " <td>33</td>\n",
  2758. " <td>106.0</td>\n",
  2759. " <td>5.0</td>\n",
  2760. " <td>6.0</td>\n",
  2761. " <td>3.0</td>\n",
  2762. " <td>3.0</td>\n",
  2763. " <td>6.0</td>\n",
  2764. " </tr>\n",
  2765. " <tr>\n",
  2766. " <th>100422</th>\n",
  2767. " <td>harpebr03</td>\n",
  2768. " <td>2015</td>\n",
  2769. " <td>1</td>\n",
  2770. " <td>WAS</td>\n",
  2771. " <td>NL</td>\n",
  2772. " <td>153</td>\n",
  2773. " <td>521</td>\n",
  2774. " <td>118</td>\n",
  2775. " <td>172</td>\n",
  2776. " <td>38</td>\n",
  2777. " <td>...</td>\n",
  2778. " <td>99.0</td>\n",
  2779. " <td>6.0</td>\n",
  2780. " <td>4.0</td>\n",
  2781. " <td>124</td>\n",
  2782. " <td>131.0</td>\n",
  2783. " <td>15.0</td>\n",
  2784. " <td>5.0</td>\n",
  2785. " <td>0.0</td>\n",
  2786. " <td>4.0</td>\n",
  2787. " <td>15.0</td>\n",
  2788. " </tr>\n",
  2789. " <tr>\n",
  2790. " <th>100950</th>\n",
  2791. " <td>ramoswi01</td>\n",
  2792. " <td>2015</td>\n",
  2793. " <td>1</td>\n",
  2794. " <td>WAS</td>\n",
  2795. " <td>NL</td>\n",
  2796. " <td>128</td>\n",
  2797. " <td>475</td>\n",
  2798. " <td>41</td>\n",
  2799. " <td>109</td>\n",
  2800. " <td>16</td>\n",
  2801. " <td>...</td>\n",
  2802. " <td>68.0</td>\n",
  2803. " <td>0.0</td>\n",
  2804. " <td>0.0</td>\n",
  2805. " <td>21</td>\n",
  2806. " <td>101.0</td>\n",
  2807. " <td>2.0</td>\n",
  2808. " <td>0.0</td>\n",
  2809. " <td>0.0</td>\n",
  2810. " <td>8.0</td>\n",
  2811. " <td>16.0</td>\n",
  2812. " </tr>\n",
  2813. " <tr>\n",
  2814. " <th>100993</th>\n",
  2815. " <td>robincl01</td>\n",
  2816. " <td>2015</td>\n",
  2817. " <td>1</td>\n",
  2818. " <td>WAS</td>\n",
  2819. " <td>NL</td>\n",
  2820. " <td>126</td>\n",
  2821. " <td>309</td>\n",
  2822. " <td>44</td>\n",
  2823. " <td>84</td>\n",
  2824. " <td>15</td>\n",
  2825. " <td>...</td>\n",
  2826. " <td>34.0</td>\n",
  2827. " <td>0.0</td>\n",
  2828. " <td>0.0</td>\n",
  2829. " <td>37</td>\n",
  2830. " <td>52.0</td>\n",
  2831. " <td>4.0</td>\n",
  2832. " <td>5.0</td>\n",
  2833. " <td>0.0</td>\n",
  2834. " <td>1.0</td>\n",
  2835. " <td>6.0</td>\n",
  2836. " </tr>\n",
  2837. " <tr>\n",
  2838. " <th>101176</th>\n",
  2839. " <td>taylomi02</td>\n",
  2840. " <td>2015</td>\n",
  2841. " <td>1</td>\n",
  2842. " <td>WAS</td>\n",
  2843. " <td>NL</td>\n",
  2844. " <td>138</td>\n",
  2845. " <td>472</td>\n",
  2846. " <td>49</td>\n",
  2847. " <td>108</td>\n",
  2848. " <td>15</td>\n",
  2849. " <td>...</td>\n",
  2850. " <td>63.0</td>\n",
  2851. " <td>16.0</td>\n",
  2852. " <td>3.0</td>\n",
  2853. " <td>35</td>\n",
  2854. " <td>158.0</td>\n",
  2855. " <td>9.0</td>\n",
  2856. " <td>1.0</td>\n",
  2857. " <td>1.0</td>\n",
  2858. " <td>2.0</td>\n",
  2859. " <td>5.0</td>\n",
  2860. " </tr>\n",
  2861. " <tr>\n",
  2862. " <th>101725</th>\n",
  2863. " <td>espinda01</td>\n",
  2864. " <td>2016</td>\n",
  2865. " <td>1</td>\n",
  2866. " <td>WAS</td>\n",
  2867. " <td>NL</td>\n",
  2868. " <td>157</td>\n",
  2869. " <td>516</td>\n",
  2870. " <td>66</td>\n",
  2871. " <td>108</td>\n",
  2872. " <td>15</td>\n",
  2873. " <td>...</td>\n",
  2874. " <td>72.0</td>\n",
  2875. " <td>9.0</td>\n",
  2876. " <td>2.0</td>\n",
  2877. " <td>54</td>\n",
  2878. " <td>174.0</td>\n",
  2879. " <td>12.0</td>\n",
  2880. " <td>20.0</td>\n",
  2881. " <td>7.0</td>\n",
  2882. " <td>4.0</td>\n",
  2883. " <td>4.0</td>\n",
  2884. " </tr>\n",
  2885. " <tr>\n",
  2886. " <th>101895</th>\n",
  2887. " <td>harpebr03</td>\n",
  2888. " <td>2016</td>\n",
  2889. " <td>1</td>\n",
  2890. " <td>WAS</td>\n",
  2891. " <td>NL</td>\n",
  2892. " <td>147</td>\n",
  2893. " <td>506</td>\n",
  2894. " <td>84</td>\n",
  2895. " <td>123</td>\n",
  2896. " <td>24</td>\n",
  2897. " <td>...</td>\n",
  2898. " <td>86.0</td>\n",
  2899. " <td>21.0</td>\n",
  2900. " <td>10.0</td>\n",
  2901. " <td>108</td>\n",
  2902. " <td>117.0</td>\n",
  2903. " <td>20.0</td>\n",
  2904. " <td>3.0</td>\n",
  2905. " <td>0.0</td>\n",
  2906. " <td>10.0</td>\n",
  2907. " <td>11.0</td>\n",
  2908. " </tr>\n",
  2909. " <tr>\n",
  2910. " <th>102245</th>\n",
  2911. " <td>murphda08</td>\n",
  2912. " <td>2016</td>\n",
  2913. " <td>1</td>\n",
  2914. " <td>WAS</td>\n",
  2915. " <td>NL</td>\n",
  2916. " <td>142</td>\n",
  2917. " <td>531</td>\n",
  2918. " <td>88</td>\n",
  2919. " <td>184</td>\n",
  2920. " <td>47</td>\n",
  2921. " <td>...</td>\n",
  2922. " <td>104.0</td>\n",
  2923. " <td>5.0</td>\n",
  2924. " <td>3.0</td>\n",
  2925. " <td>35</td>\n",
  2926. " <td>57.0</td>\n",
  2927. " <td>10.0</td>\n",
  2928. " <td>8.0</td>\n",
  2929. " <td>0.0</td>\n",
  2930. " <td>8.0</td>\n",
  2931. " <td>4.0</td>\n",
  2932. " </tr>\n",
  2933. " <tr>\n",
  2934. " <th>102429</th>\n",
  2935. " <td>ramoswi01</td>\n",
  2936. " <td>2016</td>\n",
  2937. " <td>1</td>\n",
  2938. " <td>WAS</td>\n",
  2939. " <td>NL</td>\n",
  2940. " <td>131</td>\n",
  2941. " <td>482</td>\n",
  2942. " <td>58</td>\n",
  2943. " <td>148</td>\n",
  2944. " <td>25</td>\n",
  2945. " <td>...</td>\n",
  2946. " <td>80.0</td>\n",
  2947. " <td>0.0</td>\n",
  2948. " <td>0.0</td>\n",
  2949. " <td>35</td>\n",
  2950. " <td>79.0</td>\n",
  2951. " <td>2.0</td>\n",
  2952. " <td>2.0</td>\n",
  2953. " <td>0.0</td>\n",
  2954. " <td>4.0</td>\n",
  2955. " <td>17.0</td>\n",
  2956. " </tr>\n",
  2957. " <tr>\n",
  2958. " <th>102449</th>\n",
  2959. " <td>rendoan01</td>\n",
  2960. " <td>2016</td>\n",
  2961. " <td>1</td>\n",
  2962. " <td>WAS</td>\n",
  2963. " <td>NL</td>\n",
  2964. " <td>156</td>\n",
  2965. " <td>567</td>\n",
  2966. " <td>91</td>\n",
  2967. " <td>153</td>\n",
  2968. " <td>38</td>\n",
  2969. " <td>...</td>\n",
  2970. " <td>85.0</td>\n",
  2971. " <td>12.0</td>\n",
  2972. " <td>6.0</td>\n",
  2973. " <td>65</td>\n",
  2974. " <td>117.0</td>\n",
  2975. " <td>2.0</td>\n",
  2976. " <td>7.0</td>\n",
  2977. " <td>0.0</td>\n",
  2978. " <td>8.0</td>\n",
  2979. " <td>5.0</td>\n",
  2980. " </tr>\n",
  2981. " <tr>\n",
  2982. " <th>102451</th>\n",
  2983. " <td>reverbe01</td>\n",
  2984. " <td>2016</td>\n",
  2985. " <td>1</td>\n",
  2986. " <td>WAS</td>\n",
  2987. " <td>NL</td>\n",
  2988. " <td>103</td>\n",
  2989. " <td>350</td>\n",
  2990. " <td>44</td>\n",
  2991. " <td>76</td>\n",
  2992. " <td>9</td>\n",
  2993. " <td>...</td>\n",
  2994. " <td>24.0</td>\n",
  2995. " <td>14.0</td>\n",
  2996. " <td>5.0</td>\n",
  2997. " <td>18</td>\n",
  2998. " <td>34.0</td>\n",
  2999. " <td>0.0</td>\n",
  3000. " <td>3.0</td>\n",
  3001. " <td>2.0</td>\n",
  3002. " <td>2.0</td>\n",
  3003. " <td>12.0</td>\n",
  3004. " </tr>\n",
  3005. " <tr>\n",
  3006. " <th>102472</th>\n",
  3007. " <td>robincl01</td>\n",
  3008. " <td>2016</td>\n",
  3009. " <td>1</td>\n",
  3010. " <td>WAS</td>\n",
  3011. " <td>NL</td>\n",
  3012. " <td>104</td>\n",
  3013. " <td>196</td>\n",
  3014. " <td>16</td>\n",
  3015. " <td>46</td>\n",
  3016. " <td>4</td>\n",
  3017. " <td>...</td>\n",
  3018. " <td>26.0</td>\n",
  3019. " <td>0.0</td>\n",
  3020. " <td>0.0</td>\n",
  3021. " <td>20</td>\n",
  3022. " <td>38.0</td>\n",
  3023. " <td>0.0</td>\n",
  3024. " <td>2.0</td>\n",
  3025. " <td>1.0</td>\n",
  3026. " <td>5.0</td>\n",
  3027. " <td>4.0</td>\n",
  3028. " </tr>\n",
  3029. " <tr>\n",
  3030. " <th>102763</th>\n",
  3031. " <td>werthja01</td>\n",
  3032. " <td>2016</td>\n",
  3033. " <td>1</td>\n",
  3034. " <td>WAS</td>\n",
  3035. " <td>NL</td>\n",
  3036. " <td>143</td>\n",
  3037. " <td>525</td>\n",
  3038. " <td>84</td>\n",
  3039. " <td>128</td>\n",
  3040. " <td>28</td>\n",
  3041. " <td>...</td>\n",
  3042. " <td>69.0</td>\n",
  3043. " <td>5.0</td>\n",
  3044. " <td>1.0</td>\n",
  3045. " <td>71</td>\n",
  3046. " <td>139.0</td>\n",
  3047. " <td>0.0</td>\n",
  3048. " <td>4.0</td>\n",
  3049. " <td>0.0</td>\n",
  3050. " <td>6.0</td>\n",
  3051. " <td>17.0</td>\n",
  3052. " </tr>\n",
  3053. " <tr>\n",
  3054. " <th>102812</th>\n",
  3055. " <td>zimmery01</td>\n",
  3056. " <td>2016</td>\n",
  3057. " <td>1</td>\n",
  3058. " <td>WAS</td>\n",
  3059. " <td>NL</td>\n",
  3060. " <td>115</td>\n",
  3061. " <td>427</td>\n",
  3062. " <td>60</td>\n",
  3063. " <td>93</td>\n",
  3064. " <td>18</td>\n",
  3065. " <td>...</td>\n",
  3066. " <td>46.0</td>\n",
  3067. " <td>4.0</td>\n",
  3068. " <td>1.0</td>\n",
  3069. " <td>29</td>\n",
  3070. " <td>104.0</td>\n",
  3071. " <td>1.0</td>\n",
  3072. " <td>5.0</td>\n",
  3073. " <td>0.0</td>\n",
  3074. " <td>6.0</td>\n",
  3075. " <td>12.0</td>\n",
  3076. " </tr>\n",
  3077. " </tbody>\n",
  3078. "</table>\n",
  3079. "<p>16 rows × 22 columns</p>\n",
  3080. "</div>"
  3081. ],
  3082. "text/plain": [
  3083. " playerID yearID stint teamID lgID G AB R H 2B ... \\\n",
  3084. "100193 desmoia01 2015 1 WAS NL 156 583 69 136 27 ... \n",
  3085. "100250 escobyu01 2015 1 WAS NL 139 535 75 168 25 ... \n",
  3086. "100251 espinda01 2015 1 WAS NL 118 367 59 88 21 ... \n",
  3087. "100422 harpebr03 2015 1 WAS NL 153 521 118 172 38 ... \n",
  3088. "100950 ramoswi01 2015 1 WAS NL 128 475 41 109 16 ... \n",
  3089. "100993 robincl01 2015 1 WAS NL 126 309 44 84 15 ... \n",
  3090. "101176 taylomi02 2015 1 WAS NL 138 472 49 108 15 ... \n",
  3091. "101725 espinda01 2016 1 WAS NL 157 516 66 108 15 ... \n",
  3092. "101895 harpebr03 2016 1 WAS NL 147 506 84 123 24 ... \n",
  3093. "102245 murphda08 2016 1 WAS NL 142 531 88 184 47 ... \n",
  3094. "102429 ramoswi01 2016 1 WAS NL 131 482 58 148 25 ... \n",
  3095. "102449 rendoan01 2016 1 WAS NL 156 567 91 153 38 ... \n",
  3096. "102451 reverbe01 2016 1 WAS NL 103 350 44 76 9 ... \n",
  3097. "102472 robincl01 2016 1 WAS NL 104 196 16 46 4 ... \n",
  3098. "102763 werthja01 2016 1 WAS NL 143 525 84 128 28 ... \n",
  3099. "102812 zimmery01 2016 1 WAS NL 115 427 60 93 18 ... \n",
  3100. "\n",
  3101. " RBI SB CS BB SO IBB HBP SH SF GIDP \n",
  3102. "100193 62.0 13.0 5.0 45 187.0 0.0 3.0 6.0 4.0 9.0 \n",
  3103. "100250 56.0 2.0 2.0 45 70.0 0.0 8.0 1.0 2.0 24.0 \n",
  3104. "100251 37.0 5.0 2.0 33 106.0 5.0 6.0 3.0 3.0 6.0 \n",
  3105. "100422 99.0 6.0 4.0 124 131.0 15.0 5.0 0.0 4.0 15.0 \n",
  3106. "100950 68.0 0.0 0.0 21 101.0 2.0 0.0 0.0 8.0 16.0 \n",
  3107. "100993 34.0 0.0 0.0 37 52.0 4.0 5.0 0.0 1.0 6.0 \n",
  3108. "101176 63.0 16.0 3.0 35 158.0 9.0 1.0 1.0 2.0 5.0 \n",
  3109. "101725 72.0 9.0 2.0 54 174.0 12.0 20.0 7.0 4.0 4.0 \n",
  3110. "101895 86.0 21.0 10.0 108 117.0 20.0 3.0 0.0 10.0 11.0 \n",
  3111. "102245 104.0 5.0 3.0 35 57.0 10.0 8.0 0.0 8.0 4.0 \n",
  3112. "102429 80.0 0.0 0.0 35 79.0 2.0 2.0 0.0 4.0 17.0 \n",
  3113. "102449 85.0 12.0 6.0 65 117.0 2.0 7.0 0.0 8.0 5.0 \n",
  3114. "102451 24.0 14.0 5.0 18 34.0 0.0 3.0 2.0 2.0 12.0 \n",
  3115. "102472 26.0 0.0 0.0 20 38.0 0.0 2.0 1.0 5.0 4.0 \n",
  3116. "102763 69.0 5.0 1.0 71 139.0 0.0 4.0 0.0 6.0 17.0 \n",
  3117. "102812 46.0 4.0 1.0 29 104.0 1.0 5.0 0.0 6.0 12.0 \n",
  3118. "\n",
  3119. "[16 rows x 22 columns]"
  3120. ]
  3121. },
  3122. "execution_count": 12,
  3123. "metadata": {},
  3124. "output_type": "execute_result"
  3125. }
  3126. ],
  3127. "source": [
  3128. "df_was = df[(df.yearID > 2014) & (df.teamID=='WAS') & (df.G > 99)]\n",
  3129. "df_was"
  3130. ]
  3131. },
  3132. {
  3133. "cell_type": "markdown",
  3134. "metadata": {},
  3135. "source": [
  3136. "We'll put all these things in motion later, but for now put a thumbnail on this for future reference. __NOTE__: we'll need to access the dataset that crosswalks the `PlayerID` with the actual player name and vitals, but we'll leave that as an exercise for the interested (hint: take a look [in this dataset](https://github.com/chadwickbureau/baseballdatabank/blob/master/core/People.csv))."
  3137. ]
  3138. },
  3139. {
  3140. "cell_type": "markdown",
  3141. "metadata": {},
  3142. "source": [
  3143. "## Excel\n",
  3144. "\n",
  3145. "Loading Excel data is nearly as easy as CSV data. This time we'll use a different data source and show how to access it in a slightly different manner. Instead of the _local_ file source, we will use a _remote URL_ for the resource. This will show us exactly how easy it is to seamlessly interchange various data resources. \n",
  3146. "\n",
  3147. "**DATA SOURCES**\n",
  3148. "\n",
  3149. "* [US Bureau of Transportation Statistics | Airline Employment Data](https://www.bts.gov/newsroom/may-2017-passenger-airline-employment-data) which includes data for year-over-year percentage change in employment for workers in the passenger airline industry\n",
  3150. "\n",
  3151. "To read data from the data set we will access it by URL and use the [`pandas.read_excel()` method](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html#pandas.read_excel) note we're using the `sheetname=None` parameter to read each sheet to be assigned its own key in a dictionary for easy lookup by sheet name."
  3152. ]
  3153. },
  3154. {
  3155. "cell_type": "code",
  3156. "execution_count": 13,
  3157. "metadata": {
  3158. "collapsed": true
  3159. },
  3160. "outputs": [],
  3161. "source": [
  3162. "xl = pd.read_excel(\n",
  3163. " \"https://www.bts.gov/sites/bts.dot.gov/files/docs/newsroom/206581/airline-employment-press-tables-web.xlsx\",\n",
  3164. " sheetname=None)"
  3165. ]
  3166. },
  3167. {
  3168. "cell_type": "markdown",
  3169. "metadata": {},
  3170. "source": [
  3171. "Notice now, if we want to access the _sheet_ called `Table1` we can easily do this in a Pythonic way much like any other dictionary. The result is the DataFrame representation of that _sheet_."
  3172. ]
  3173. },
  3174. {
  3175. "cell_type": "code",
  3176. "execution_count": 14,
  3177. "metadata": {},
  3178. "outputs": [
  3179. {
  3180. "data": {
  3181. "text/html": [
  3182. "<div>\n",
  3183. "<style>\n",
  3184. " .dataframe thead tr:only-child th {\n",
  3185. " text-align: right;\n",
  3186. " }\n",
  3187. "\n",
  3188. " .dataframe thead th {\n",
  3189. " text-align: left;\n",
  3190. " }\n",
  3191. "\n",
  3192. " .dataframe tbody tr th {\n",
  3193. " vertical-align: top;\n",
  3194. " }\n",
  3195. "</style>\n",
  3196. "<table border=\"1\" class=\"dataframe\">\n",
  3197. " <thead>\n",
  3198. " <tr style=\"text-align: right;\">\n",
  3199. " <th></th>\n",
  3200. " <th>Table 1: Yearly Change in Scheduled Passenger Airline Full-time Equivalent Employees* by Airline Group</th>\n",
  3201. " <th>Unnamed: 1</th>\n",
  3202. " <th>Unnamed: 2</th>\n",
  3203. " <th>Unnamed: 3</th>\n",
  3204. " <th>Unnamed: 4</th>\n",
  3205. " <th>Unnamed: 5</th>\n",
  3206. " </tr>\n",
  3207. " </thead>\n",
  3208. " <tbody>\n",
  3209. " <tr>\n",
  3210. " <th>0</th>\n",
  3211. " <td>Most recent 13 months - percent change from sa...</td>\n",
  3212. " <td>NaN</td>\n",
  3213. " <td>NaN</td>\n",
  3214. " <td>NaN</td>\n",
  3215. " <td>NaN</td>\n",
  3216. " <td>NaN</td>\n",
  3217. " </tr>\n",
  3218. " <tr>\n",
  3219. " <th>1</th>\n",
  3220. " <td>NaN</td>\n",
  3221. " <td>Network Airlines</td>\n",
  3222. " <td>Low-Cost Airlines</td>\n",
  3223. " <td>Regional Airlines</td>\n",
  3224. " <td>Other Airlines</td>\n",
  3225. " <td>All Passenger Airlines **</td>\n",
  3226. " </tr>\n",
  3227. " <tr>\n",
  3228. " <th>2</th>\n",
  3229. " <td>May 2015 - May 2016</td>\n",
  3230. " <td>2.3</td>\n",
  3231. " <td>10.7</td>\n",
  3232. " <td>0.2</td>\n",
  3233. " <td>9.3</td>\n",
  3234. " <td>3.7</td>\n",
  3235. " </tr>\n",
  3236. " <tr>\n",
  3237. " <th>3</th>\n",
  3238. " <td>Jun 2015 - Jun 2016</td>\n",
  3239. " <td>2.3</td>\n",
  3240. " <td>11</td>\n",
  3241. " <td>0.9</td>\n",
  3242. " <td>10.6</td>\n",
  3243. " <td>3.9</td>\n",
  3244. " </tr>\n",
  3245. " <tr>\n",
  3246. " <th>4</th>\n",
  3247. " <td>Jul 2015 - Jul 2016</td>\n",
  3248. " <td>2.4</td>\n",
  3249. " <td>11.3</td>\n",
  3250. " <td>3.3</td>\n",
  3251. " <td>11.2</td>\n",
  3252. " <td>4.3</td>\n",
  3253. " </tr>\n",
  3254. " <tr>\n",
  3255. " <th>5</th>\n",
  3256. " <td>Aug 2015 - Aug 2016</td>\n",
  3257. " <td>2.5</td>\n",
  3258. " <td>11</td>\n",
  3259. " <td>3.3</td>\n",
  3260. " <td>11.9</td>\n",
  3261. " <td>4.3</td>\n",
  3262. " </tr>\n",
  3263. " <tr>\n",
  3264. " <th>6</th>\n",
  3265. " <td>Sep 2015 - Sep 2016</td>\n",
  3266. " <td>2.6</td>\n",
  3267. " <td>10.6</td>\n",
  3268. " <td>2.9</td>\n",
  3269. " <td>13</td>\n",
  3270. " <td>4.3</td>\n",
  3271. " </tr>\n",
  3272. " <tr>\n",
  3273. " <th>7</th>\n",
  3274. " <td>Oct 2015 - Oct 2016</td>\n",
  3275. " <td>2.7</td>\n",
  3276. " <td>10.3</td>\n",
  3277. " <td>0.3</td>\n",
  3278. " <td>12.7</td>\n",
  3279. " <td>4</td>\n",
  3280. " </tr>\n",
  3281. " <tr>\n",
  3282. " <th>8</th>\n",
  3283. " <td>Nov 2015 - Nov 2016</td>\n",
  3284. " <td>2.3</td>\n",
  3285. " <td>9.8</td>\n",
  3286. " <td>0.2</td>\n",
  3287. " <td>13.5</td>\n",
  3288. " <td>3.7</td>\n",
  3289. " </tr>\n",
  3290. " <tr>\n",
  3291. " <th>9</th>\n",
  3292. " <td>Dec 2015 - Dec 2016</td>\n",
  3293. " <td>2.4</td>\n",
  3294. " <td>9.5</td>\n",
  3295. " <td>0.2</td>\n",
  3296. " <td>13.7</td>\n",
  3297. " <td>3.7</td>\n",
  3298. " </tr>\n",
  3299. " <tr>\n",
  3300. " <th>10</th>\n",
  3301. " <td>Jan 2016 - Jan 2017</td>\n",
  3302. " <td>2.3</td>\n",
  3303. " <td>9.7</td>\n",
  3304. " <td>1.9</td>\n",
  3305. " <td>12.7</td>\n",
  3306. " <td>3.9</td>\n",
  3307. " </tr>\n",
  3308. " <tr>\n",
  3309. " <th>11</th>\n",
  3310. " <td>Feb 2016 - Feb 2017</td>\n",
  3311. " <td>2.4</td>\n",
  3312. " <td>9.4</td>\n",
  3313. " <td>2.4</td>\n",
  3314. " <td>11.8</td>\n",
  3315. " <td>3.9</td>\n",
  3316. " </tr>\n",
  3317. " <tr>\n",
  3318. " <th>12</th>\n",
  3319. " <td>Mar 2016 - Mar 2017</td>\n",
  3320. " <td>2.7</td>\n",
  3321. " <td>9.1</td>\n",
  3322. " <td>2</td>\n",
  3323. " <td>11.7</td>\n",
  3324. " <td>4</td>\n",
  3325. " </tr>\n",
  3326. " <tr>\n",
  3327. " <th>13</th>\n",
  3328. " <td>Apr 2016 - Apr 2017</td>\n",
  3329. " <td>2.6</td>\n",
  3330. " <td>8.5</td>\n",
  3331. " <td>2.1</td>\n",
  3332. " <td>10.7</td>\n",
  3333. " <td>3.9</td>\n",
  3334. " </tr>\n",
  3335. " <tr>\n",
  3336. " <th>14</th>\n",
  3337. " <td>May 2016 - May 2017</td>\n",
  3338. " <td>2.4</td>\n",
  3339. " <td>8.3</td>\n",
  3340. " <td>2.5</td>\n",
  3341. " <td>4.2</td>\n",
  3342. " <td>3.6</td>\n",
  3343. " </tr>\n",
  3344. " <tr>\n",
  3345. " <th>15</th>\n",
  3346. " <td>Source: Bureau of Transportation Statistics</td>\n",
  3347. " <td>NaN</td>\n",
  3348. " <td>NaN</td>\n",
  3349. " <td>NaN</td>\n",
  3350. " <td>NaN</td>\n",
  3351. " <td>NaN</td>\n",
  3352. " </tr>\n",
  3353. " <tr>\n",
  3354. " <th>16</th>\n",
  3355. " <td>* Full-time Equivalent Employee (FTE) calculat...</td>\n",
  3356. " <td>NaN</td>\n",
  3357. " <td>NaN</td>\n",
  3358. " <td>NaN</td>\n",
  3359. " <td>NaN</td>\n",
  3360. " <td>NaN</td>\n",
  3361. " </tr>\n",
  3362. " <tr>\n",
  3363. " <th>17</th>\n",
  3364. " <td>** Includes network, low-cost, regional and ot...</td>\n",
  3365. " <td>NaN</td>\n",
  3366. " <td>NaN</td>\n",
  3367. " <td>NaN</td>\n",
  3368. " <td>NaN</td>\n",
  3369. " <td>NaN</td>\n",
  3370. " </tr>\n",
  3371. " <tr>\n",
  3372. " <th>18</th>\n",
  3373. " <td>Note: Percent changes based on numbers prior t...</td>\n",
  3374. " <td>NaN</td>\n",
  3375. " <td>NaN</td>\n",
  3376. " <td>NaN</td>\n",
  3377. " <td>NaN</td>\n",
  3378. " <td>NaN</td>\n",
  3379. " </tr>\n",
  3380. " <tr>\n",
  3381. " <th>19</th>\n",
  3382. " <td>Note: See Table 2 for all passenger airlines, ...</td>\n",
  3383. " <td>NaN</td>\n",
  3384. " <td>NaN</td>\n",
  3385. " <td>NaN</td>\n",
  3386. " <td>NaN</td>\n",
  3387. " <td>NaN</td>\n",
  3388. " </tr>\n",
  3389. " </tbody>\n",
  3390. "</table>\n",
  3391. "</div>"
  3392. ],
  3393. "text/plain": [
  3394. " Table 1: Yearly Change in Scheduled Passenger Airline Full-time Equivalent Employees* by Airline Group \\\n",
  3395. "0 Most recent 13 months - percent change from sa... \n",
  3396. "1 NaN \n",
  3397. "2 May 2015 - May 2016 \n",
  3398. "3 Jun 2015 - Jun 2016 \n",
  3399. "4 Jul 2015 - Jul 2016 \n",
  3400. "5 Aug 2015 - Aug 2016 \n",
  3401. "6 Sep 2015 - Sep 2016 \n",
  3402. "7 Oct 2015 - Oct 2016 \n",
  3403. "8 Nov 2015 - Nov 2016 \n",
  3404. "9 Dec 2015 - Dec 2016 \n",
  3405. "10 Jan 2016 - Jan 2017 \n",
  3406. "11 Feb 2016 - Feb 2017 \n",
  3407. "12 Mar 2016 - Mar 2017 \n",
  3408. "13 Apr 2016 - Apr 2017 \n",
  3409. "14 May 2016 - May 2017 \n",
  3410. "15 Source: Bureau of Transportation Statistics \n",
  3411. "16 * Full-time Equivalent Employee (FTE) calculat... \n",
  3412. "17 ** Includes network, low-cost, regional and ot... \n",
  3413. "18 Note: Percent changes based on numbers prior t... \n",
  3414. "19 Note: See Table 2 for all passenger airlines, ... \n",
  3415. "\n",
  3416. " Unnamed: 1 Unnamed: 2 Unnamed: 3 Unnamed: 4 \\\n",
  3417. "0 NaN NaN NaN NaN \n",
  3418. "1 Network Airlines Low-Cost Airlines Regional Airlines Other Airlines \n",
  3419. "2 2.3 10.7 0.2 9.3 \n",
  3420. "3 2.3 11 0.9 10.6 \n",
  3421. "4 2.4 11.3 3.3 11.2 \n",
  3422. "5 2.5 11 3.3 11.9 \n",
  3423. "6 2.6 10.6 2.9 13 \n",
  3424. "7 2.7 10.3 0.3 12.7 \n",
  3425. "8 2.3 9.8 0.2 13.5 \n",
  3426. "9 2.4 9.5 0.2 13.7 \n",
  3427. "10 2.3 9.7 1.9 12.7 \n",
  3428. "11 2.4 9.4 2.4 11.8 \n",
  3429. "12 2.7 9.1 2 11.7 \n",
  3430. "13 2.6 8.5 2.1 10.7 \n",
  3431. "14 2.4 8.3 2.5 4.2 \n",
  3432. "15 NaN NaN NaN NaN \n",
  3433. "16 NaN NaN NaN NaN \n",
  3434. "17 NaN NaN NaN NaN \n",
  3435. "18 NaN NaN NaN NaN \n",
  3436. "19 NaN NaN NaN NaN \n",
  3437. "\n",
  3438. " Unnamed: 5 \n",
  3439. "0 NaN \n",
  3440. "1 All Passenger Airlines ** \n",
  3441. "2 3.7 \n",
  3442. "3 3.9 \n",
  3443. "4 4.3 \n",
  3444. "5 4.3 \n",
  3445. "6 4.3 \n",
  3446. "7 4 \n",
  3447. "8 3.7 \n",
  3448. "9 3.7 \n",
  3449. "10 3.9 \n",
  3450. "11 3.9 \n",
  3451. "12 4 \n",
  3452. "13 3.9 \n",
  3453. "14 3.6 \n",
  3454. "15 NaN \n",
  3455. "16 NaN \n",
  3456. "17 NaN \n",
  3457. "18 NaN \n",
  3458. "19 NaN "
  3459. ]
  3460. },
  3461. "execution_count": 14,
  3462. "metadata": {},
  3463. "output_type": "execute_result"
  3464. }
  3465. ],
  3466. "source": [
  3467. "xl_tbl1 = xl['Table1']\n",
  3468. "xl_tbl1"
  3469. ]
  3470. },
  3471. {
  3472. "cell_type": "markdown",
  3473. "metadata": {},
  3474. "source": [
  3475. "One problem we have here is that the data is not exactly as clean as we want it to be. We'll spend more time talking about the `iloc`() method in the next section, but for now, let's get a flavor for how we might clean this up so it is more usable."
  3476. ]
  3477. },
  3478. {
  3479. "cell_type": "code",
  3480. "execution_count": 15,
  3481. "metadata": {},
  3482. "outputs": [
  3483. {
  3484. "name": "stdout",
  3485. "output_type": "stream",
  3486. "text": [
  3487. " Table 1: Yearly Change in Scheduled Passenger Airline Full-time Equivalent Employees* by Airline Group\n",
  3488. "2 May 2015 - May 2016 \n",
  3489. "3 Jun 2015 - Jun 2016 \n",
  3490. "4 Jul 2015 - Jul 2016 \n",
  3491. "5 Aug 2015 - Aug 2016 \n",
  3492. "6 Sep 2015 - Sep 2016 \n",
  3493. "7 Oct 2015 - Oct 2016 \n",
  3494. "8 Nov 2015 - Nov 2016 \n",
  3495. "9 Dec 2015 - Dec 2016 \n",
  3496. "10 Jan 2016 - Jan 2017 \n",
  3497. "11 Feb 2016 - Feb 2017 \n",
  3498. "12 Mar 2016 - Mar 2017 \n",
  3499. "13 Apr 2016 - Apr 2017 \n",
  3500. "14 May 2016 - May 2017 \n",
  3501. "Unnamed: 1 Network Airlines\n",
  3502. "Unnamed: 2 Low-Cost Airlines\n",
  3503. "Unnamed: 3 Regional Airlines\n",
  3504. "Unnamed: 4 Other Airlines\n",
  3505. "Unnamed: 5 All Passenger Airlines **\n",
  3506. "Name: 1, dtype: object\n"
  3507. ]
  3508. }
  3509. ],
  3510. "source": [
  3511. "# lets select the (row) index \n",
  3512. "idx = xl_tbl1.iloc[2:15, 0:1]\n",
  3513. "\n",
  3514. "# lets select the (col) index\n",
  3515. "col = xl_tbl1.iloc[1,1:]\n",
  3516. "\n",
  3517. "print(idx)\n",
  3518. "print(col)"
  3519. ]
  3520. },
  3521. {
  3522. "cell_type": "code",
  3523. "execution_count": 16,
  3524. "metadata": {},
  3525. "outputs": [
  3526. {
  3527. "data": {
  3528. "text/plain": [
  3529. "Index(['May 2015 - May 2016', 'Jun 2015 - Jun 2016', 'Jul 2015 - Jul 2016',\n",
  3530. " 'Aug 2015 - Aug 2016', 'Sep 2015 - Sep 2016', 'Oct 2015 - Oct 2016',\n",
  3531. " 'Nov 2015 - Nov 2016', 'Dec 2015 - Dec 2016', 'Jan 2016 - Jan 2017',\n",
  3532. " 'Feb 2016 - Feb 2017', 'Mar 2016 - Mar 2017', 'Apr 2016 - Apr 2017',\n",
  3533. " 'May 2016 - May 2017'],\n",
  3534. " dtype='object')"
  3535. ]
  3536. },
  3537. "execution_count": 16,
  3538. "metadata": {},
  3539. "output_type": "execute_result"
  3540. }
  3541. ],
  3542. "source": [
  3543. "# we'll create the index object\n",
  3544. "idxs = pd.Index([v[0] for v in idx.values])\n",
  3545. "idxs"
  3546. ]
  3547. },
  3548. {
  3549. "cell_type": "code",
  3550. "execution_count": 17,
  3551. "metadata": {},
  3552. "outputs": [
  3553. {
  3554. "data": {
  3555. "text/plain": [
  3556. "['Network Airlines',\n",
  3557. " 'Low-Cost Airlines',\n",
  3558. " 'Regional Airlines',\n",
  3559. " 'Other Airlines',\n",
  3560. " 'All Passenger Airlines **']"
  3561. ]
  3562. },
  3563. "execution_count": 17,
  3564. "metadata": {},
  3565. "output_type": "execute_result"
  3566. }
  3567. ],
  3568. "source": [
  3569. "# set the columns\n",
  3570. "cols = [v for v in col.values]\n",
  3571. "cols"
  3572. ]
  3573. },
  3574. {
  3575. "cell_type": "code",
  3576. "execution_count": 18,
  3577. "metadata": {},
  3578. "outputs": [
  3579. {
  3580. "data": {
  3581. "text/plain": [
  3582. "array([[2.3, 10.7, 0.2, 9.3, 3.7],\n",
  3583. " [2.3, 11, 0.9, 10.6, 3.9],\n",
  3584. " [2.4, 11.3, 3.3, 11.2, 4.3],\n",
  3585. " [2.5, 11, 3.3, 11.9, 4.3],\n",
  3586. " [2.6, 10.6, 2.9, 13, 4.3],\n",
  3587. " [2.7, 10.3, 0.3, 12.7, 4],\n",
  3588. " [2.3, 9.8, 0.2, 13.5, 3.7],\n",
  3589. " [2.4, 9.5, 0.2, 13.7, 3.7],\n",
  3590. " [2.3, 9.7, 1.9, 12.7, 3.9],\n",
  3591. " [2.4, 9.4, 2.4, 11.8, 3.9],\n",
  3592. " [2.7, 9.1, 2, 11.7, 4],\n",
  3593. " [2.6, 8.5, 2.1, 10.7, 3.9],\n",
  3594. " [2.4, 8.3, 2.5, 4.2, 3.6]], dtype=object)"
  3595. ]
  3596. },
  3597. "execution_count": 18,
  3598. "metadata": {},
  3599. "output_type": "execute_result"
  3600. }
  3601. ],
  3602. "source": [
  3603. "# now for the data\n",
  3604. "data = xl_tbl1.iloc[2:15,1:].values\n",
  3605. "data"
  3606. ]
  3607. },
  3608. {
  3609. "cell_type": "code",
  3610. "execution_count": 19,
  3611. "metadata": {},
  3612. "outputs": [
  3613. {
  3614. "data": {
  3615. "text/html": [
  3616. "<div>\n",
  3617. "<style>\n",
  3618. " .dataframe thead tr:only-child th {\n",
  3619. " text-align: right;\n",
  3620. " }\n",
  3621. "\n",
  3622. " .dataframe thead th {\n",
  3623. " text-align: left;\n",
  3624. " }\n",
  3625. "\n",
  3626. " .dataframe tbody tr th {\n",
  3627. " vertical-align: top;\n",
  3628. " }\n",
  3629. "</style>\n",
  3630. "<table border=\"1\" class=\"dataframe\">\n",
  3631. " <thead>\n",
  3632. " <tr style=\"text-align: right;\">\n",
  3633. " <th></th>\n",
  3634. " <th>Network Airlines</th>\n",
  3635. " <th>Low-Cost Airlines</th>\n",
  3636. " <th>Regional Airlines</th>\n",
  3637. " <th>Other Airlines</th>\n",
  3638. " <th>All Passenger Airlines **</th>\n",
  3639. " </tr>\n",
  3640. " </thead>\n",
  3641. " <tbody>\n",
  3642. " <tr>\n",
  3643. " <th>May 2015 - May 2016</th>\n",
  3644. " <td>2.3</td>\n",
  3645. " <td>10.7</td>\n",
  3646. " <td>0.2</td>\n",
  3647. " <td>9.3</td>\n",
  3648. " <td>3.7</td>\n",
  3649. " </tr>\n",
  3650. " <tr>\n",
  3651. " <th>Jun 2015 - Jun 2016</th>\n",
  3652. " <td>2.3</td>\n",
  3653. " <td>11</td>\n",
  3654. " <td>0.9</td>\n",
  3655. " <td>10.6</td>\n",
  3656. " <td>3.9</td>\n",
  3657. " </tr>\n",
  3658. " <tr>\n",
  3659. " <th>Jul 2015 - Jul 2016</th>\n",
  3660. " <td>2.4</td>\n",
  3661. " <td>11.3</td>\n",
  3662. " <td>3.3</td>\n",
  3663. " <td>11.2</td>\n",
  3664. " <td>4.3</td>\n",
  3665. " </tr>\n",
  3666. " <tr>\n",
  3667. " <th>Aug 2015 - Aug 2016</th>\n",
  3668. " <td>2.5</td>\n",
  3669. " <td>11</td>\n",
  3670. " <td>3.3</td>\n",
  3671. " <td>11.9</td>\n",
  3672. " <td>4.3</td>\n",
  3673. " </tr>\n",
  3674. " <tr>\n",
  3675. " <th>Sep 2015 - Sep 2016</th>\n",
  3676. " <td>2.6</td>\n",
  3677. " <td>10.6</td>\n",
  3678. " <td>2.9</td>\n",
  3679. " <td>13</td>\n",
  3680. " <td>4.3</td>\n",
  3681. " </tr>\n",
  3682. " <tr>\n",
  3683. " <th>Oct 2015 - Oct 2016</th>\n",
  3684. " <td>2.7</td>\n",
  3685. " <td>10.3</td>\n",
  3686. " <td>0.3</td>\n",
  3687. " <td>12.7</td>\n",
  3688. " <td>4</td>\n",
  3689. " </tr>\n",
  3690. " <tr>\n",
  3691. " <th>Nov 2015 - Nov 2016</th>\n",
  3692. " <td>2.3</td>\n",
  3693. " <td>9.8</td>\n",
  3694. " <td>0.2</td>\n",
  3695. " <td>13.5</td>\n",
  3696. " <td>3.7</td>\n",
  3697. " </tr>\n",
  3698. " <tr>\n",
  3699. " <th>Dec 2015 - Dec 2016</th>\n",
  3700. " <td>2.4</td>\n",
  3701. " <td>9.5</td>\n",
  3702. " <td>0.2</td>\n",
  3703. " <td>13.7</td>\n",
  3704. " <td>3.7</td>\n",
  3705. " </tr>\n",
  3706. " <tr>\n",
  3707. " <th>Jan 2016 - Jan 2017</th>\n",
  3708. " <td>2.3</td>\n",
  3709. " <td>9.7</td>\n",
  3710. " <td>1.9</td>\n",
  3711. " <td>12.7</td>\n",
  3712. " <td>3.9</td>\n",
  3713. " </tr>\n",
  3714. " <tr>\n",
  3715. " <th>Feb 2016 - Feb 2017</th>\n",
  3716. " <td>2.4</td>\n",
  3717. " <td>9.4</td>\n",
  3718. " <td>2.4</td>\n",
  3719. " <td>11.8</td>\n",
  3720. " <td>3.9</td>\n",
  3721. " </tr>\n",
  3722. " <tr>\n",
  3723. " <th>Mar 2016 - Mar 2017</th>\n",
  3724. " <td>2.7</td>\n",
  3725. " <td>9.1</td>\n",
  3726. " <td>2</td>\n",
  3727. " <td>11.7</td>\n",
  3728. " <td>4</td>\n",
  3729. " </tr>\n",
  3730. " <tr>\n",
  3731. " <th>Apr 2016 - Apr 2017</th>\n",
  3732. " <td>2.6</td>\n",
  3733. " <td>8.5</td>\n",
  3734. " <td>2.1</td>\n",
  3735. " <td>10.7</td>\n",
  3736. " <td>3.9</td>\n",
  3737. " </tr>\n",
  3738. " <tr>\n",
  3739. " <th>May 2016 - May 2017</th>\n",
  3740. " <td>2.4</td>\n",
  3741. " <td>8.3</td>\n",
  3742. " <td>2.5</td>\n",
  3743. " <td>4.2</td>\n",
  3744. " <td>3.6</td>\n",
  3745. " </tr>\n",
  3746. " </tbody>\n",
  3747. "</table>\n",
  3748. "</div>"
  3749. ],
  3750. "text/plain": [
  3751. " Network Airlines Low-Cost Airlines Regional Airlines \\\n",
  3752. "May 2015 - May 2016 2.3 10.7 0.2 \n",
  3753. "Jun 2015 - Jun 2016 2.3 11 0.9 \n",
  3754. "Jul 2015 - Jul 2016 2.4 11.3 3.3 \n",
  3755. "Aug 2015 - Aug 2016 2.5 11 3.3 \n",
  3756. "Sep 2015 - Sep 2016 2.6 10.6 2.9 \n",
  3757. "Oct 2015 - Oct 2016 2.7 10.3 0.3 \n",
  3758. "Nov 2015 - Nov 2016 2.3 9.8 0.2 \n",
  3759. "Dec 2015 - Dec 2016 2.4 9.5 0.2 \n",
  3760. "Jan 2016 - Jan 2017 2.3 9.7 1.9 \n",
  3761. "Feb 2016 - Feb 2017 2.4 9.4 2.4 \n",
  3762. "Mar 2016 - Mar 2017 2.7 9.1 2 \n",
  3763. "Apr 2016 - Apr 2017 2.6 8.5 2.1 \n",
  3764. "May 2016 - May 2017 2.4 8.3 2.5 \n",
  3765. "\n",
  3766. " Other Airlines All Passenger Airlines ** \n",
  3767. "May 2015 - May 2016 9.3 3.7 \n",
  3768. "Jun 2015 - Jun 2016 10.6 3.9 \n",
  3769. "Jul 2015 - Jul 2016 11.2 4.3 \n",
  3770. "Aug 2015 - Aug 2016 11.9 4.3 \n",
  3771. "Sep 2015 - Sep 2016 13 4.3 \n",
  3772. "Oct 2015 - Oct 2016 12.7 4 \n",
  3773. "Nov 2015 - Nov 2016 13.5 3.7 \n",
  3774. "Dec 2015 - Dec 2016 13.7 3.7 \n",
  3775. "Jan 2016 - Jan 2017 12.7 3.9 \n",
  3776. "Feb 2016 - Feb 2017 11.8 3.9 \n",
  3777. "Mar 2016 - Mar 2017 11.7 4 \n",
  3778. "Apr 2016 - Apr 2017 10.7 3.9 \n",
  3779. "May 2016 - May 2017 4.2 3.6 "
  3780. ]
  3781. },
  3782. "execution_count": 19,
  3783. "metadata": {},
  3784. "output_type": "execute_result"
  3785. }
  3786. ],
  3787. "source": [
  3788. "# putting it all together ...\n",
  3789. "df_tbl1 = pd.DataFrame(data=xl_tbl1.iloc[2:15,1:].values,\n",
  3790. " columns=[v for v in col.values], \n",
  3791. " index=pd.Index([v[0] for v in idx.values]))\n",
  3792. "df_tbl1"
  3793. ]
  3794. },
  3795. {
  3796. "cell_type": "code",
  3797. "execution_count": 20,
  3798. "metadata": {},
  3799. "outputs": [
  3800. {
  3801. "data": {
  3802. "text/plain": [
  3803. "May 2015 - May 2016 2.3\n",
  3804. "Jun 2015 - Jun 2016 2.3\n",
  3805. "Jul 2015 - Jul 2016 2.4\n",
  3806. "Aug 2015 - Aug 2016 2.5\n",
  3807. "Sep 2015 - Sep 2016 2.6\n",
  3808. "Oct 2015 - Oct 2016 2.7\n",
  3809. "Nov 2015 - Nov 2016 2.3\n",
  3810. "Dec 2015 - Dec 2016 2.4\n",
  3811. "Jan 2016 - Jan 2017 2.3\n",
  3812. "Feb 2016 - Feb 2017 2.4\n",
  3813. "Mar 2016 - Mar 2017 2.7\n",
  3814. "Apr 2016 - Apr 2017 2.6\n",
  3815. "May 2016 - May 2017 2.4\n",
  3816. "Name: Network Airlines, dtype: object"
  3817. ]
  3818. },
  3819. "execution_count": 20,
  3820. "metadata": {},
  3821. "output_type": "execute_result"
  3822. }
  3823. ],
  3824. "source": [
  3825. "df_tbl1['Network Airlines']"
  3826. ]
  3827. },
  3828. {
  3829. "cell_type": "markdown",
  3830. "metadata": {},
  3831. "source": [
  3832. "## JSON\n",
  3833. "\n",
  3834. "JSON has become a standard format format for many web data sources. It is succinct, readable and very portable -- there are libraries in nearly every modern language that can parse JSON, Python being no exception. We'll load a remote JSON data source to demonstrate remote access as well as the capabilities of using Pandas to load such a source.\n",
  3835. "\n",
  3836. "**JSON DATA SOURCE**\n",
  3837. "\n",
  3838. "* [Quotes for developers](https://github.com/fortrabbit/quotes) by _fortrabbit_\n",
  3839. "\n",
  3840. "If we haven't noticed the pattern yet, loading JSON data will come as no surprise via the [`pandas.read_json()`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html#pandas.read_json).\n",
  3841. "\n",
  3842. "With JSON data you may get the best results with relatively _flat_ JSON objects. If you need to obtain different results (or you're getting results that are not as expected), you might instead into the `orient` parameter to get different resulting DataFrames. We'll load the data as-is and reshape our DataFrame for some extra practice."
  3843. ]
  3844. },
  3845. {
  3846. "cell_type": "code",
  3847. "execution_count": 21,
  3848. "metadata": {},
  3849. "outputs": [
  3850. {
  3851. "data": {
  3852. "text/html": [
  3853. "<div>\n",
  3854. "<style>\n",
  3855. " .dataframe thead tr:only-child th {\n",
  3856. " text-align: right;\n",
  3857. " }\n",
  3858. "\n",
  3859. " .dataframe thead th {\n",
  3860. " text-align: left;\n",
  3861. " }\n",
  3862. "\n",
  3863. " .dataframe tbody tr th {\n",
  3864. " vertical-align: top;\n",
  3865. " }\n",
  3866. "</style>\n",
  3867. "<table border=\"1\" class=\"dataframe\">\n",
  3868. " <thead>\n",
  3869. " <tr style=\"text-align: right;\">\n",
  3870. " <th></th>\n",
  3871. " <th>author</th>\n",
  3872. " <th>text</th>\n",
  3873. " </tr>\n",
  3874. " </thead>\n",
  3875. " <tbody>\n",
  3876. " <tr>\n",
  3877. " <th>0</th>\n",
  3878. " <td>Martin Golding</td>\n",
  3879. " <td>Always code as if the guy who ends up maintain...</td>\n",
  3880. " </tr>\n",
  3881. " <tr>\n",
  3882. " <th>1</th>\n",
  3883. " <td>Unknown</td>\n",
  3884. " <td>All computers wait at the same speed.</td>\n",
  3885. " </tr>\n",
  3886. " <tr>\n",
  3887. " <th>2</th>\n",
  3888. " <td>Unknown</td>\n",
  3889. " <td>A misplaced decimal point will always end up w...</td>\n",
  3890. " </tr>\n",
  3891. " <tr>\n",
  3892. " <th>3</th>\n",
  3893. " <td>Unknown</td>\n",
  3894. " <td>A good programmer looks both ways before cross...</td>\n",
  3895. " </tr>\n",
  3896. " <tr>\n",
  3897. " <th>4</th>\n",
  3898. " <td>Unknown</td>\n",
  3899. " <td>A computer program does what you tell it to do...</td>\n",
  3900. " </tr>\n",
  3901. " <tr>\n",
  3902. " <th>5</th>\n",
  3903. " <td>Unknown</td>\n",
  3904. " <td>\"Intel Inside\" is a Government Warning require...</td>\n",
  3905. " </tr>\n",
  3906. " <tr>\n",
  3907. " <th>6</th>\n",
  3908. " <td>Arthur Godfrey</td>\n",
  3909. " <td>Common sense gets a lot of credit that belongs...</td>\n",
  3910. " </tr>\n",
  3911. " <tr>\n",
  3912. " <th>7</th>\n",
  3913. " <td>Unknown</td>\n",
  3914. " <td>Chuck Norris doesn’t go hunting. Chuck Norris ...</td>\n",
  3915. " </tr>\n",
  3916. " <tr>\n",
  3917. " <th>8</th>\n",
  3918. " <td>Unknown</td>\n",
  3919. " <td>Chuck Norris counted to infinity... twice.</td>\n",
  3920. " </tr>\n",
  3921. " <tr>\n",
  3922. " <th>9</th>\n",
  3923. " <td>Unknown</td>\n",
  3924. " <td>C is quirky, flawed, and an enormous success.</td>\n",
  3925. " </tr>\n",
  3926. " <tr>\n",
  3927. " <th>10</th>\n",
  3928. " <td>Unknown</td>\n",
  3929. " <td>Beta is Latin for still doesn’t work.</td>\n",
  3930. " </tr>\n",
  3931. " <tr>\n",
  3932. " <th>11</th>\n",
  3933. " <td>Unknown</td>\n",
  3934. " <td>ASCII stupid question, get a stupid ANSI!</td>\n",
  3935. " </tr>\n",
  3936. " <tr>\n",
  3937. " <th>12</th>\n",
  3938. " <td>Unknown</td>\n",
  3939. " <td>Artificial Intelligence usually beats natural ...</td>\n",
  3940. " </tr>\n",
  3941. " <tr>\n",
  3942. " <th>13</th>\n",
  3943. " <td>Ted Nelson</td>\n",
  3944. " <td>Any fool can use a computer. Many do.</td>\n",
  3945. " </tr>\n",
  3946. " <tr>\n",
  3947. " <th>14</th>\n",
  3948. " <td>Unknown</td>\n",
  3949. " <td>Hey! It compiles! Ship it!</td>\n",
  3950. " </tr>\n",
  3951. " <tr>\n",
  3952. " <th>15</th>\n",
  3953. " <td>Martin Luther King Junior</td>\n",
  3954. " <td>Hate cannot drive out hate; only love can do t...</td>\n",
  3955. " </tr>\n",
  3956. " <tr>\n",
  3957. " <th>16</th>\n",
  3958. " <td>Unknown</td>\n",
  3959. " <td>Guns don’t kill people. Chuck Norris kills peo...</td>\n",
  3960. " </tr>\n",
  3961. " <tr>\n",
  3962. " <th>17</th>\n",
  3963. " <td>Unknown</td>\n",
  3964. " <td>God is real, unless declared integer.</td>\n",
  3965. " </tr>\n",
  3966. " <tr>\n",
  3967. " <th>18</th>\n",
  3968. " <td>John Johnson</td>\n",
  3969. " <td>First, solve the problem. Then, write the code.</td>\n",
  3970. " </tr>\n",
  3971. " <tr>\n",
  3972. " <th>19</th>\n",
  3973. " <td>Oscar Wilde</td>\n",
  3974. " <td>Experience is the name everyone gives to their...</td>\n",
  3975. " </tr>\n",
  3976. " <tr>\n",
  3977. " <th>20</th>\n",
  3978. " <td>Miguel de Icaza</td>\n",
  3979. " <td>Every piece of software written today is likel...</td>\n",
  3980. " </tr>\n",
  3981. " <tr>\n",
  3982. " <th>21</th>\n",
  3983. " <td>Unknown</td>\n",
  3984. " <td>Computers make very fast, very accurate mistakes.</td>\n",
  3985. " </tr>\n",
  3986. " <tr>\n",
  3987. " <th>22</th>\n",
  3988. " <td>Unknown</td>\n",
  3989. " <td>Computers do not solve problems, they execute ...</td>\n",
  3990. " </tr>\n",
  3991. " <tr>\n",
  3992. " <th>23</th>\n",
  3993. " <td>Unknown</td>\n",
  3994. " <td>I have NOT lost my mind—I have it backed up on...</td>\n",
  3995. " </tr>\n",
  3996. " <tr>\n",
  3997. " <th>24</th>\n",
  3998. " <td>Unknown</td>\n",
  3999. " <td>If brute force doesn’t solve your problems, th...</td>\n",
  4000. " </tr>\n",
  4001. " <tr>\n",
  4002. " <th>25</th>\n",
  4003. " <td>Unknown</td>\n",
  4004. " <td>It works on my machine.</td>\n",
  4005. " </tr>\n",
  4006. " <tr>\n",
  4007. " <th>26</th>\n",
  4008. " <td>Unknown</td>\n",
  4009. " <td>Java is, in many ways, C++??.</td>\n",
  4010. " </tr>\n",
  4011. " <tr>\n",
  4012. " <th>27</th>\n",
  4013. " <td>Unknown</td>\n",
  4014. " <td>Keyboard not found...Press any key to continue.</td>\n",
  4015. " </tr>\n",
  4016. " <tr>\n",
  4017. " <th>28</th>\n",
  4018. " <td>Unknown</td>\n",
  4019. " <td>Life would be so much easier if we only had th...</td>\n",
  4020. " </tr>\n",
  4021. " <tr>\n",
  4022. " <th>29</th>\n",
  4023. " <td>Unknown</td>\n",
  4024. " <td>Mac users swear by their Mac, PC users swear a...</td>\n",
  4025. " </tr>\n",
  4026. " <tr>\n",
  4027. " <th>...</th>\n",
  4028. " <td>...</td>\n",
  4029. " <td>...</td>\n",
  4030. " </tr>\n",
  4031. " <tr>\n",
  4032. " <th>159</th>\n",
  4033. " <td>Paul Graham</td>\n",
  4034. " <td>OO programming offers a sustainable way to wri...</td>\n",
  4035. " </tr>\n",
  4036. " <tr>\n",
  4037. " <th>160</th>\n",
  4038. " <td>Nikita Popov</td>\n",
  4039. " <td>Ruby is rubbish! PHP is phpantastic!</td>\n",
  4040. " </tr>\n",
  4041. " <tr>\n",
  4042. " <th>161</th>\n",
  4043. " <td>Douglas Adams</td>\n",
  4044. " <td>So long and thanks for all the fish!</td>\n",
  4045. " </tr>\n",
  4046. " <tr>\n",
  4047. " <th>162</th>\n",
  4048. " <td>Cicero</td>\n",
  4049. " <td>If I had more time, I would have written a sho...</td>\n",
  4050. " </tr>\n",
  4051. " <tr>\n",
  4052. " <th>163</th>\n",
  4053. " <td>Jeff Atwood</td>\n",
  4054. " <td>The best reaction to \"this is confusing, where...</td>\n",
  4055. " </tr>\n",
  4056. " <tr>\n",
  4057. " <th>164</th>\n",
  4058. " <td>Jeff Atwood</td>\n",
  4059. " <td>The older I get, the more I believe that the o...</td>\n",
  4060. " </tr>\n",
  4061. " <tr>\n",
  4062. " <th>165</th>\n",
  4063. " <td>Douglas Crockford</td>\n",
  4064. " <td>\"That hardly ever happens\" is another way of s...</td>\n",
  4065. " </tr>\n",
  4066. " <tr>\n",
  4067. " <th>166</th>\n",
  4068. " <td>Anna Debenham</td>\n",
  4069. " <td>Hello, PHP, my old friend.</td>\n",
  4070. " </tr>\n",
  4071. " <tr>\n",
  4072. " <th>167</th>\n",
  4073. " <td>Melvin Conway</td>\n",
  4074. " <td>Organizations which design systems are constra...</td>\n",
  4075. " </tr>\n",
  4076. " <tr>\n",
  4077. " <th>168</th>\n",
  4078. " <td>Melvin Conway</td>\n",
  4079. " <td>In design, complexity is toxic.</td>\n",
  4080. " </tr>\n",
  4081. " <tr>\n",
  4082. " <th>169</th>\n",
  4083. " <td>Jeffrey Zeldman</td>\n",
  4084. " <td>Good is the enemy of great, but great is the e...</td>\n",
  4085. " </tr>\n",
  4086. " <tr>\n",
  4087. " <th>170</th>\n",
  4088. " <td>Rick Lemons</td>\n",
  4089. " <td>Don't make the user provide information that t...</td>\n",
  4090. " </tr>\n",
  4091. " <tr>\n",
  4092. " <th>171</th>\n",
  4093. " <td>Donald E. Knuth</td>\n",
  4094. " <td>You're bound to be unhappy if you optimize eve...</td>\n",
  4095. " </tr>\n",
  4096. " <tr>\n",
  4097. " <th>172</th>\n",
  4098. " <td>Anna Nachesa</td>\n",
  4099. " <td>If the programmers like each other, they play ...</td>\n",
  4100. " </tr>\n",
  4101. " <tr>\n",
  4102. " <th>173</th>\n",
  4103. " <td>Edsger W. Dijkstra</td>\n",
  4104. " <td>Simplicity is prerequisite for reliability.</td>\n",
  4105. " </tr>\n",
  4106. " <tr>\n",
  4107. " <th>174</th>\n",
  4108. " <td>Jordi Boggiano</td>\n",
  4109. " <td>Focus on WHY instead of WHAT in your code will...</td>\n",
  4110. " </tr>\n",
  4111. " <tr>\n",
  4112. " <th>175</th>\n",
  4113. " <td>Andrei Herasimchuk</td>\n",
  4114. " <td>The best engineers I know are artists at heart...</td>\n",
  4115. " </tr>\n",
  4116. " <tr>\n",
  4117. " <th>176</th>\n",
  4118. " <td>Barry Boehm</td>\n",
  4119. " <td>Poor management can increase software costs mo...</td>\n",
  4120. " </tr>\n",
  4121. " <tr>\n",
  4122. " <th>177</th>\n",
  4123. " <td>Daniel Bryant</td>\n",
  4124. " <td>If you can't deploy your services independentl...</td>\n",
  4125. " </tr>\n",
  4126. " <tr>\n",
  4127. " <th>178</th>\n",
  4128. " <td>Daniel Bryant</td>\n",
  4129. " <td>If you can't deploy your services independentl...</td>\n",
  4130. " </tr>\n",
  4131. " <tr>\n",
  4132. " <th>179</th>\n",
  4133. " <td>Jeff Atwood</td>\n",
  4134. " <td>No one hates software more than software devel...</td>\n",
  4135. " </tr>\n",
  4136. " <tr>\n",
  4137. " <th>180</th>\n",
  4138. " <td>Robert C. Martin</td>\n",
  4139. " <td>The proper use of comments is to compensate fo...</td>\n",
  4140. " </tr>\n",
  4141. " <tr>\n",
  4142. " <th>181</th>\n",
  4143. " <td>Cory House</td>\n",
  4144. " <td>Code is like humor. When you have to explain i...</td>\n",
  4145. " </tr>\n",
  4146. " <tr>\n",
  4147. " <th>182</th>\n",
  4148. " <td>Steve Maguire</td>\n",
  4149. " <td>Fix the cause, not the symptom.</td>\n",
  4150. " </tr>\n",
  4151. " <tr>\n",
  4152. " <th>183</th>\n",
  4153. " <td>David Heinemeier Hansson</td>\n",
  4154. " <td>Programmers are constantly making things more ...</td>\n",
  4155. " </tr>\n",
  4156. " <tr>\n",
  4157. " <th>184</th>\n",
  4158. " <td>Linus Torvalds</td>\n",
  4159. " <td>People will realize that software is not a pro...</td>\n",
  4160. " </tr>\n",
  4161. " <tr>\n",
  4162. " <th>185</th>\n",
  4163. " <td>Ron Fein</td>\n",
  4164. " <td>Design is choosing how you will fail.</td>\n",
  4165. " </tr>\n",
  4166. " <tr>\n",
  4167. " <th>186</th>\n",
  4168. " <td>Steve Jobs</td>\n",
  4169. " <td>Focus is saying no to 1000 good ideas.</td>\n",
  4170. " </tr>\n",
  4171. " <tr>\n",
  4172. " <th>187</th>\n",
  4173. " <td>Ron Jeffries</td>\n",
  4174. " <td>Code never lies, comments sometimes do.</td>\n",
  4175. " </tr>\n",
  4176. " <tr>\n",
  4177. " <th>188</th>\n",
  4178. " <td>Unknown</td>\n",
  4179. " <td>Be careful with each other, so you can be dang...</td>\n",
  4180. " </tr>\n",
  4181. " </tbody>\n",
  4182. "</table>\n",
  4183. "<p>189 rows × 2 columns</p>\n",
  4184. "</div>"
  4185. ],
  4186. "text/plain": [
  4187. " author \\\n",
  4188. "0 Martin Golding \n",
  4189. "1 Unknown \n",
  4190. "2 Unknown \n",
  4191. "3 Unknown \n",
  4192. "4 Unknown \n",
  4193. "5 Unknown \n",
  4194. "6 Arthur Godfrey \n",
  4195. "7 Unknown \n",
  4196. "8 Unknown \n",
  4197. "9 Unknown \n",
  4198. "10 Unknown \n",
  4199. "11 Unknown \n",
  4200. "12 Unknown \n",
  4201. "13 Ted Nelson \n",
  4202. "14 Unknown \n",
  4203. "15 Martin Luther King Junior \n",
  4204. "16 Unknown \n",
  4205. "17 Unknown \n",
  4206. "18 John Johnson \n",
  4207. "19 Oscar Wilde \n",
  4208. "20 Miguel de Icaza \n",
  4209. "21 Unknown \n",
  4210. "22 Unknown \n",
  4211. "23 Unknown \n",
  4212. "24 Unknown \n",
  4213. "25 Unknown \n",
  4214. "26 Unknown \n",
  4215. "27 Unknown \n",
  4216. "28 Unknown \n",
  4217. "29 Unknown \n",
  4218. ".. ... \n",
  4219. "159 Paul Graham \n",
  4220. "160 Nikita Popov \n",
  4221. "161 Douglas Adams \n",
  4222. "162 Cicero \n",
  4223. "163 Jeff Atwood \n",
  4224. "164 Jeff Atwood \n",
  4225. "165 Douglas Crockford \n",
  4226. "166 Anna Debenham \n",
  4227. "167 Melvin Conway \n",
  4228. "168 Melvin Conway \n",
  4229. "169 Jeffrey Zeldman \n",
  4230. "170 Rick Lemons \n",
  4231. "171 Donald E. Knuth \n",
  4232. "172 Anna Nachesa \n",
  4233. "173 Edsger W. Dijkstra \n",
  4234. "174 Jordi Boggiano \n",
  4235. "175 Andrei Herasimchuk \n",
  4236. "176 Barry Boehm \n",
  4237. "177 Daniel Bryant \n",
  4238. "178 Daniel Bryant \n",
  4239. "179 Jeff Atwood \n",
  4240. "180 Robert C. Martin \n",
  4241. "181 Cory House \n",
  4242. "182 Steve Maguire \n",
  4243. "183 David Heinemeier Hansson \n",
  4244. "184 Linus Torvalds \n",
  4245. "185 Ron Fein \n",
  4246. "186 Steve Jobs \n",
  4247. "187 Ron Jeffries \n",
  4248. "188 Unknown \n",
  4249. "\n",
  4250. " text \n",
  4251. "0 Always code as if the guy who ends up maintain... \n",
  4252. "1 All computers wait at the same speed. \n",
  4253. "2 A misplaced decimal point will always end up w... \n",
  4254. "3 A good programmer looks both ways before cross... \n",
  4255. "4 A computer program does what you tell it to do... \n",
  4256. "5 \"Intel Inside\" is a Government Warning require... \n",
  4257. "6 Common sense gets a lot of credit that belongs... \n",
  4258. "7 Chuck Norris doesn’t go hunting. Chuck Norris ... \n",
  4259. "8 Chuck Norris counted to infinity... twice. \n",
  4260. "9 C is quirky, flawed, and an enormous success. \n",
  4261. "10 Beta is Latin for still doesn’t work. \n",
  4262. "11 ASCII stupid question, get a stupid ANSI! \n",
  4263. "12 Artificial Intelligence usually beats natural ... \n",
  4264. "13 Any fool can use a computer. Many do. \n",
  4265. "14 Hey! It compiles! Ship it! \n",
  4266. "15 Hate cannot drive out hate; only love can do t... \n",
  4267. "16 Guns don’t kill people. Chuck Norris kills peo... \n",
  4268. "17 God is real, unless declared integer. \n",
  4269. "18 First, solve the problem. Then, write the code. \n",
  4270. "19 Experience is the name everyone gives to their... \n",
  4271. "20 Every piece of software written today is likel... \n",
  4272. "21 Computers make very fast, very accurate mistakes. \n",
  4273. "22 Computers do not solve problems, they execute ... \n",
  4274. "23 I have NOT lost my mind—I have it backed up on... \n",
  4275. "24 If brute force doesn’t solve your problems, th... \n",
  4276. "25 It works on my machine. \n",
  4277. "26 Java is, in many ways, C++??. \n",
  4278. "27 Keyboard not found...Press any key to continue. \n",
  4279. "28 Life would be so much easier if we only had th... \n",
  4280. "29 Mac users swear by their Mac, PC users swear a... \n",
  4281. ".. ... \n",
  4282. "159 OO programming offers a sustainable way to wri... \n",
  4283. "160 Ruby is rubbish! PHP is phpantastic! \n",
  4284. "161 So long and thanks for all the fish! \n",
  4285. "162 If I had more time, I would have written a sho... \n",
  4286. "163 The best reaction to \"this is confusing, where... \n",
  4287. "164 The older I get, the more I believe that the o... \n",
  4288. "165 \"That hardly ever happens\" is another way of s... \n",
  4289. "166 Hello, PHP, my old friend. \n",
  4290. "167 Organizations which design systems are constra... \n",
  4291. "168 In design, complexity is toxic. \n",
  4292. "169 Good is the enemy of great, but great is the e... \n",
  4293. "170 Don't make the user provide information that t... \n",
  4294. "171 You're bound to be unhappy if you optimize eve... \n",
  4295. "172 If the programmers like each other, they play ... \n",
  4296. "173 Simplicity is prerequisite for reliability. \n",
  4297. "174 Focus on WHY instead of WHAT in your code will... \n",
  4298. "175 The best engineers I know are artists at heart... \n",
  4299. "176 Poor management can increase software costs mo... \n",
  4300. "177 If you can't deploy your services independentl... \n",
  4301. "178 If you can't deploy your services independentl... \n",
  4302. "179 No one hates software more than software devel... \n",
  4303. "180 The proper use of comments is to compensate fo... \n",
  4304. "181 Code is like humor. When you have to explain i... \n",
  4305. "182 Fix the cause, not the symptom. \n",
  4306. "183 Programmers are constantly making things more ... \n",
  4307. "184 People will realize that software is not a pro... \n",
  4308. "185 Design is choosing how you will fail. \n",
  4309. "186 Focus is saying no to 1000 good ideas. \n",
  4310. "187 Code never lies, comments sometimes do. \n",
  4311. "188 Be careful with each other, so you can be dang... \n",
  4312. "\n",
  4313. "[189 rows x 2 columns]"
  4314. ]
  4315. },
  4316. "execution_count": 21,
  4317. "metadata": {},
  4318. "output_type": "execute_result"
  4319. }
  4320. ],
  4321. "source": [
  4322. "df = pd.read_json(\n",
  4323. " \"https://raw.githubusercontent.com/fortrabbit/quotes/master/quotes.json\")\n",
  4324. "df"
  4325. ]
  4326. },
  4327. {
  4328. "cell_type": "markdown",
  4329. "metadata": {},
  4330. "source": [
  4331. "Though not a best practice, say we wanted to set the author as the index and the quote of the text the value. In this dataset, we're going to have repeated index values, and it might make sense if we wanted to access the data this way, but be _very careful doing this in practice_."
  4332. ]
  4333. },
  4334. {
  4335. "cell_type": "code",
  4336. "execution_count": 22,
  4337. "metadata": {},
  4338. "outputs": [
  4339. {
  4340. "data": {
  4341. "text/html": [
  4342. "<div>\n",
  4343. "<style>\n",
  4344. " .dataframe thead tr:only-child th {\n",
  4345. " text-align: right;\n",
  4346. " }\n",
  4347. "\n",
  4348. " .dataframe thead th {\n",
  4349. " text-align: left;\n",
  4350. " }\n",
  4351. "\n",
  4352. " .dataframe tbody tr th {\n",
  4353. " vertical-align: top;\n",
  4354. " }\n",
  4355. "</style>\n",
  4356. "<table border=\"1\" class=\"dataframe\">\n",
  4357. " <thead>\n",
  4358. " <tr style=\"text-align: right;\">\n",
  4359. " <th></th>\n",
  4360. " <th>text</th>\n",
  4361. " </tr>\n",
  4362. " <tr>\n",
  4363. " <th>author</th>\n",
  4364. " <th></th>\n",
  4365. " </tr>\n",
  4366. " </thead>\n",
  4367. " <tbody>\n",
  4368. " <tr>\n",
  4369. " <th>Martin Golding</th>\n",
  4370. " <td>Always code as if the guy who ends up maintain...</td>\n",
  4371. " </tr>\n",
  4372. " <tr>\n",
  4373. " <th>Unknown</th>\n",
  4374. " <td>All computers wait at the same speed.</td>\n",
  4375. " </tr>\n",
  4376. " <tr>\n",
  4377. " <th>Unknown</th>\n",
  4378. " <td>A misplaced decimal point will always end up w...</td>\n",
  4379. " </tr>\n",
  4380. " <tr>\n",
  4381. " <th>Unknown</th>\n",
  4382. " <td>A good programmer looks both ways before cross...</td>\n",
  4383. " </tr>\n",
  4384. " <tr>\n",
  4385. " <th>Unknown</th>\n",
  4386. " <td>A computer program does what you tell it to do...</td>\n",
  4387. " </tr>\n",
  4388. " <tr>\n",
  4389. " <th>Unknown</th>\n",
  4390. " <td>\"Intel Inside\" is a Government Warning require...</td>\n",
  4391. " </tr>\n",
  4392. " <tr>\n",
  4393. " <th>Arthur Godfrey</th>\n",
  4394. " <td>Common sense gets a lot of credit that belongs...</td>\n",
  4395. " </tr>\n",
  4396. " <tr>\n",
  4397. " <th>Unknown</th>\n",
  4398. " <td>Chuck Norris doesn’t go hunting. Chuck Norris ...</td>\n",
  4399. " </tr>\n",
  4400. " <tr>\n",
  4401. " <th>Unknown</th>\n",
  4402. " <td>Chuck Norris counted to infinity... twice.</td>\n",
  4403. " </tr>\n",
  4404. " <tr>\n",
  4405. " <th>Unknown</th>\n",
  4406. " <td>C is quirky, flawed, and an enormous success.</td>\n",
  4407. " </tr>\n",
  4408. " <tr>\n",
  4409. " <th>Unknown</th>\n",
  4410. " <td>Beta is Latin for still doesn’t work.</td>\n",
  4411. " </tr>\n",
  4412. " <tr>\n",
  4413. " <th>Unknown</th>\n",
  4414. " <td>ASCII stupid question, get a stupid ANSI!</td>\n",
  4415. " </tr>\n",
  4416. " <tr>\n",
  4417. " <th>Unknown</th>\n",
  4418. " <td>Artificial Intelligence usually beats natural ...</td>\n",
  4419. " </tr>\n",
  4420. " <tr>\n",
  4421. " <th>Ted Nelson</th>\n",
  4422. " <td>Any fool can use a computer. Many do.</td>\n",
  4423. " </tr>\n",
  4424. " <tr>\n",
  4425. " <th>Unknown</th>\n",
  4426. " <td>Hey! It compiles! Ship it!</td>\n",
  4427. " </tr>\n",
  4428. " <tr>\n",
  4429. " <th>Martin Luther King Junior</th>\n",
  4430. " <td>Hate cannot drive out hate; only love can do t...</td>\n",
  4431. " </tr>\n",
  4432. " <tr>\n",
  4433. " <th>Unknown</th>\n",
  4434. " <td>Guns don’t kill people. Chuck Norris kills peo...</td>\n",
  4435. " </tr>\n",
  4436. " <tr>\n",
  4437. " <th>Unknown</th>\n",
  4438. " <td>God is real, unless declared integer.</td>\n",
  4439. " </tr>\n",
  4440. " <tr>\n",
  4441. " <th>John Johnson</th>\n",
  4442. " <td>First, solve the problem. Then, write the code.</td>\n",
  4443. " </tr>\n",
  4444. " <tr>\n",
  4445. " <th>Oscar Wilde</th>\n",
  4446. " <td>Experience is the name everyone gives to their...</td>\n",
  4447. " </tr>\n",
  4448. " <tr>\n",
  4449. " <th>Miguel de Icaza</th>\n",
  4450. " <td>Every piece of software written today is likel...</td>\n",
  4451. " </tr>\n",
  4452. " <tr>\n",
  4453. " <th>Unknown</th>\n",
  4454. " <td>Computers make very fast, very accurate mistakes.</td>\n",
  4455. " </tr>\n",
  4456. " <tr>\n",
  4457. " <th>Unknown</th>\n",
  4458. " <td>Computers do not solve problems, they execute ...</td>\n",
  4459. " </tr>\n",
  4460. " <tr>\n",
  4461. " <th>Unknown</th>\n",
  4462. " <td>I have NOT lost my mind—I have it backed up on...</td>\n",
  4463. " </tr>\n",
  4464. " <tr>\n",
  4465. " <th>Unknown</th>\n",
  4466. " <td>If brute force doesn’t solve your problems, th...</td>\n",
  4467. " </tr>\n",
  4468. " <tr>\n",
  4469. " <th>Unknown</th>\n",
  4470. " <td>It works on my machine.</td>\n",
  4471. " </tr>\n",
  4472. " <tr>\n",
  4473. " <th>Unknown</th>\n",
  4474. " <td>Java is, in many ways, C++??.</td>\n",
  4475. " </tr>\n",
  4476. " <tr>\n",
  4477. " <th>Unknown</th>\n",
  4478. " <td>Keyboard not found...Press any key to continue.</td>\n",
  4479. " </tr>\n",
  4480. " <tr>\n",
  4481. " <th>Unknown</th>\n",
  4482. " <td>Life would be so much easier if we only had th...</td>\n",
  4483. " </tr>\n",
  4484. " <tr>\n",
  4485. " <th>Unknown</th>\n",
  4486. " <td>Mac users swear by their Mac, PC users swear a...</td>\n",
  4487. " </tr>\n",
  4488. " <tr>\n",
  4489. " <th>...</th>\n",
  4490. " <td>...</td>\n",
  4491. " </tr>\n",
  4492. " <tr>\n",
  4493. " <th>Paul Graham</th>\n",
  4494. " <td>OO programming offers a sustainable way to wri...</td>\n",
  4495. " </tr>\n",
  4496. " <tr>\n",
  4497. " <th>Nikita Popov</th>\n",
  4498. " <td>Ruby is rubbish! PHP is phpantastic!</td>\n",
  4499. " </tr>\n",
  4500. " <tr>\n",
  4501. " <th>Douglas Adams</th>\n",
  4502. " <td>So long and thanks for all the fish!</td>\n",
  4503. " </tr>\n",
  4504. " <tr>\n",
  4505. " <th>Cicero</th>\n",
  4506. " <td>If I had more time, I would have written a sho...</td>\n",
  4507. " </tr>\n",
  4508. " <tr>\n",
  4509. " <th>Jeff Atwood</th>\n",
  4510. " <td>The best reaction to \"this is confusing, where...</td>\n",
  4511. " </tr>\n",
  4512. " <tr>\n",
  4513. " <th>Jeff Atwood</th>\n",
  4514. " <td>The older I get, the more I believe that the o...</td>\n",
  4515. " </tr>\n",
  4516. " <tr>\n",
  4517. " <th>Douglas Crockford</th>\n",
  4518. " <td>\"That hardly ever happens\" is another way of s...</td>\n",
  4519. " </tr>\n",
  4520. " <tr>\n",
  4521. " <th>Anna Debenham</th>\n",
  4522. " <td>Hello, PHP, my old friend.</td>\n",
  4523. " </tr>\n",
  4524. " <tr>\n",
  4525. " <th>Melvin Conway</th>\n",
  4526. " <td>Organizations which design systems are constra...</td>\n",
  4527. " </tr>\n",
  4528. " <tr>\n",
  4529. " <th>Melvin Conway</th>\n",
  4530. " <td>In design, complexity is toxic.</td>\n",
  4531. " </tr>\n",
  4532. " <tr>\n",
  4533. " <th>Jeffrey Zeldman</th>\n",
  4534. " <td>Good is the enemy of great, but great is the e...</td>\n",
  4535. " </tr>\n",
  4536. " <tr>\n",
  4537. " <th>Rick Lemons</th>\n",
  4538. " <td>Don't make the user provide information that t...</td>\n",
  4539. " </tr>\n",
  4540. " <tr>\n",
  4541. " <th>Donald E. Knuth</th>\n",
  4542. " <td>You're bound to be unhappy if you optimize eve...</td>\n",
  4543. " </tr>\n",
  4544. " <tr>\n",
  4545. " <th>Anna Nachesa</th>\n",
  4546. " <td>If the programmers like each other, they play ...</td>\n",
  4547. " </tr>\n",
  4548. " <tr>\n",
  4549. " <th>Edsger W. Dijkstra</th>\n",
  4550. " <td>Simplicity is prerequisite for reliability.</td>\n",
  4551. " </tr>\n",
  4552. " <tr>\n",
  4553. " <th>Jordi Boggiano</th>\n",
  4554. " <td>Focus on WHY instead of WHAT in your code will...</td>\n",
  4555. " </tr>\n",
  4556. " <tr>\n",
  4557. " <th>Andrei Herasimchuk</th>\n",
  4558. " <td>The best engineers I know are artists at heart...</td>\n",
  4559. " </tr>\n",
  4560. " <tr>\n",
  4561. " <th>Barry Boehm</th>\n",
  4562. " <td>Poor management can increase software costs mo...</td>\n",
  4563. " </tr>\n",
  4564. " <tr>\n",
  4565. " <th>Daniel Bryant</th>\n",
  4566. " <td>If you can't deploy your services independentl...</td>\n",
  4567. " </tr>\n",
  4568. " <tr>\n",
  4569. " <th>Daniel Bryant</th>\n",
  4570. " <td>If you can't deploy your services independentl...</td>\n",
  4571. " </tr>\n",
  4572. " <tr>\n",
  4573. " <th>Jeff Atwood</th>\n",
  4574. " <td>No one hates software more than software devel...</td>\n",
  4575. " </tr>\n",
  4576. " <tr>\n",
  4577. " <th>Robert C. Martin</th>\n",
  4578. " <td>The proper use of comments is to compensate fo...</td>\n",
  4579. " </tr>\n",
  4580. " <tr>\n",
  4581. " <th>Cory House</th>\n",
  4582. " <td>Code is like humor. When you have to explain i...</td>\n",
  4583. " </tr>\n",
  4584. " <tr>\n",
  4585. " <th>Steve Maguire</th>\n",
  4586. " <td>Fix the cause, not the symptom.</td>\n",
  4587. " </tr>\n",
  4588. " <tr>\n",
  4589. " <th>David Heinemeier Hansson</th>\n",
  4590. " <td>Programmers are constantly making things more ...</td>\n",
  4591. " </tr>\n",
  4592. " <tr>\n",
  4593. " <th>Linus Torvalds</th>\n",
  4594. " <td>People will realize that software is not a pro...</td>\n",
  4595. " </tr>\n",
  4596. " <tr>\n",
  4597. " <th>Ron Fein</th>\n",
  4598. " <td>Design is choosing how you will fail.</td>\n",
  4599. " </tr>\n",
  4600. " <tr>\n",
  4601. " <th>Steve Jobs</th>\n",
  4602. " <td>Focus is saying no to 1000 good ideas.</td>\n",
  4603. " </tr>\n",
  4604. " <tr>\n",
  4605. " <th>Ron Jeffries</th>\n",
  4606. " <td>Code never lies, comments sometimes do.</td>\n",
  4607. " </tr>\n",
  4608. " <tr>\n",
  4609. " <th>Unknown</th>\n",
  4610. " <td>Be careful with each other, so you can be dang...</td>\n",
  4611. " </tr>\n",
  4612. " </tbody>\n",
  4613. "</table>\n",
  4614. "<p>189 rows × 1 columns</p>\n",
  4615. "</div>"
  4616. ],
  4617. "text/plain": [
  4618. " text\n",
  4619. "author \n",
  4620. "Martin Golding Always code as if the guy who ends up maintain...\n",
  4621. "Unknown All computers wait at the same speed.\n",
  4622. "Unknown A misplaced decimal point will always end up w...\n",
  4623. "Unknown A good programmer looks both ways before cross...\n",
  4624. "Unknown A computer program does what you tell it to do...\n",
  4625. "Unknown \"Intel Inside\" is a Government Warning require...\n",
  4626. "Arthur Godfrey Common sense gets a lot of credit that belongs...\n",
  4627. "Unknown Chuck Norris doesn’t go hunting. Chuck Norris ...\n",
  4628. "Unknown Chuck Norris counted to infinity... twice.\n",
  4629. "Unknown C is quirky, flawed, and an enormous success.\n",
  4630. "Unknown Beta is Latin for still doesn’t work.\n",
  4631. "Unknown ASCII stupid question, get a stupid ANSI!\n",
  4632. "Unknown Artificial Intelligence usually beats natural ...\n",
  4633. "Ted Nelson Any fool can use a computer. Many do.\n",
  4634. "Unknown Hey! It compiles! Ship it!\n",
  4635. "Martin Luther King Junior Hate cannot drive out hate; only love can do t...\n",
  4636. "Unknown Guns don’t kill people. Chuck Norris kills peo...\n",
  4637. "Unknown God is real, unless declared integer.\n",
  4638. "John Johnson First, solve the problem. Then, write the code.\n",
  4639. "Oscar Wilde Experience is the name everyone gives to their...\n",
  4640. "Miguel de Icaza Every piece of software written today is likel...\n",
  4641. "Unknown Computers make very fast, very accurate mistakes.\n",
  4642. "Unknown Computers do not solve problems, they execute ...\n",
  4643. "Unknown I have NOT lost my mind—I have it backed up on...\n",
  4644. "Unknown If brute force doesn’t solve your problems, th...\n",
  4645. "Unknown It works on my machine.\n",
  4646. "Unknown Java is, in many ways, C++??.\n",
  4647. "Unknown Keyboard not found...Press any key to continue.\n",
  4648. "Unknown Life would be so much easier if we only had th...\n",
  4649. "Unknown Mac users swear by their Mac, PC users swear a...\n",
  4650. "... ...\n",
  4651. "Paul Graham OO programming offers a sustainable way to wri...\n",
  4652. "Nikita Popov Ruby is rubbish! PHP is phpantastic!\n",
  4653. "Douglas Adams So long and thanks for all the fish!\n",
  4654. "Cicero If I had more time, I would have written a sho...\n",
  4655. "Jeff Atwood The best reaction to \"this is confusing, where...\n",
  4656. "Jeff Atwood The older I get, the more I believe that the o...\n",
  4657. "Douglas Crockford \"That hardly ever happens\" is another way of s...\n",
  4658. "Anna Debenham Hello, PHP, my old friend.\n",
  4659. "Melvin Conway Organizations which design systems are constra...\n",
  4660. "Melvin Conway In design, complexity is toxic.\n",
  4661. "Jeffrey Zeldman Good is the enemy of great, but great is the e...\n",
  4662. "Rick Lemons Don't make the user provide information that t...\n",
  4663. "Donald E. Knuth You're bound to be unhappy if you optimize eve...\n",
  4664. "Anna Nachesa If the programmers like each other, they play ...\n",
  4665. "Edsger W. Dijkstra Simplicity is prerequisite for reliability.\n",
  4666. "Jordi Boggiano Focus on WHY instead of WHAT in your code will...\n",
  4667. "Andrei Herasimchuk The best engineers I know are artists at heart...\n",
  4668. "Barry Boehm Poor management can increase software costs mo...\n",
  4669. "Daniel Bryant If you can't deploy your services independentl...\n",
  4670. "Daniel Bryant If you can't deploy your services independentl...\n",
  4671. "Jeff Atwood No one hates software more than software devel...\n",
  4672. "Robert C. Martin The proper use of comments is to compensate fo...\n",
  4673. "Cory House Code is like humor. When you have to explain i...\n",
  4674. "Steve Maguire Fix the cause, not the symptom.\n",
  4675. "David Heinemeier Hansson Programmers are constantly making things more ...\n",
  4676. "Linus Torvalds People will realize that software is not a pro...\n",
  4677. "Ron Fein Design is choosing how you will fail.\n",
  4678. "Steve Jobs Focus is saying no to 1000 good ideas.\n",
  4679. "Ron Jeffries Code never lies, comments sometimes do.\n",
  4680. "Unknown Be careful with each other, so you can be dang...\n",
  4681. "\n",
  4682. "[189 rows x 1 columns]"
  4683. ]
  4684. },
  4685. "execution_count": 22,
  4686. "metadata": {},
  4687. "output_type": "execute_result"
  4688. }
  4689. ],
  4690. "source": [
  4691. "df1 = df.set_index(df['author']).drop('author', axis=1)\n",
  4692. "df1"
  4693. ]
  4694. },
  4695. {
  4696. "cell_type": "markdown",
  4697. "metadata": {},
  4698. "source": [
  4699. "Though we haven't talked about it, there is a very interesting and useful mechanism for filtering data using the [`apply()`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.apply.html#pandas.Series.apply) method. In this case, we're going to write a cute anonymous function that finds all the quotes by the author `Unknown` with `java` in the quote."
  4700. ]
  4701. },
  4702. {
  4703. "cell_type": "code",
  4704. "execution_count": 23,
  4705. "metadata": {
  4706. "scrolled": true
  4707. },
  4708. "outputs": [
  4709. {
  4710. "data": {
  4711. "text/html": [
  4712. "<div>\n",
  4713. "<style>\n",
  4714. " .dataframe thead tr:only-child th {\n",
  4715. " text-align: right;\n",
  4716. " }\n",
  4717. "\n",
  4718. " .dataframe thead th {\n",
  4719. " text-align: left;\n",
  4720. " }\n",
  4721. "\n",
  4722. " .dataframe tbody tr th {\n",
  4723. " vertical-align: top;\n",
  4724. " }\n",
  4725. "</style>\n",
  4726. "<table border=\"1\" class=\"dataframe\">\n",
  4727. " <thead>\n",
  4728. " <tr style=\"text-align: right;\">\n",
  4729. " <th></th>\n",
  4730. " <th>text</th>\n",
  4731. " </tr>\n",
  4732. " <tr>\n",
  4733. " <th>author</th>\n",
  4734. " <th></th>\n",
  4735. " </tr>\n",
  4736. " </thead>\n",
  4737. " <tbody>\n",
  4738. " <tr>\n",
  4739. " <th>Unknown</th>\n",
  4740. " <td>Java is, in many ways, C++??.</td>\n",
  4741. " </tr>\n",
  4742. " </tbody>\n",
  4743. "</table>\n",
  4744. "</div>"
  4745. ],
  4746. "text/plain": [
  4747. " text\n",
  4748. "author \n",
  4749. "Unknown Java is, in many ways, C++??."
  4750. ]
  4751. },
  4752. "execution_count": 23,
  4753. "metadata": {},
  4754. "output_type": "execute_result"
  4755. }
  4756. ],
  4757. "source": [
  4758. "df1.loc[\"Unknown\"][df1.loc[\"Unknown\"][\"text\"]\n",
  4759. " .apply(lambda v: \"jav\" in v.lower())]"
  4760. ]
  4761. },
  4762. {
  4763. "cell_type": "markdown",
  4764. "metadata": {},
  4765. "source": [
  4766. "## SQL"
  4767. ]
  4768. },
  4769. {
  4770. "cell_type": "markdown",
  4771. "metadata": {
  4772. "collapsed": true
  4773. },
  4774. "source": [
  4775. "Loading SQL data into a DataFrame is also supported by Pandas. You might need to take a look at the [SQLAlchemy](http://www.sqlalchemy.org/) and the [documentation on creating database engines](http://docs.sqlalchemy.org/en/latest/core/engines.html), as this is the framework supported directly by Pandas.\n",
  4776. "\n",
  4777. "**SQL DATA SOURCE**\n",
  4778. "\n",
  4779. "* [Jeopardy! Data Analysis](https://github.com/cmohamma/jeopardy) - a sqlite database by _cmohamma_\n",
  4780. "\n",
  4781. "This file contains a number of tables that contain the Jeopardy! game clues, players, wins, categories, etc. We will only use a fraction of the data to demonstrate the SQL capabilities.\n",
  4782. "\n",
  4783. "Our example will use a [SQLite database](https://sqlite.org/) so we can demonstrate the example in a standalone context. We'll show reading a table in full using the [`read_sql_table()`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql_table.html#pandas.read_sql_table) and then how to do ad hoc queries using [`read_sql_query()`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql_query.html#pandas.read_sql_query)."
  4784. ]
  4785. },
  4786. {
  4787. "cell_type": "code",
  4788. "execution_count": 24,
  4789. "metadata": {
  4790. "collapsed": true
  4791. },
  4792. "outputs": [],
  4793. "source": [
  4794. "from sqlalchemy import create_engine\n",
  4795. "engine = create_engine('sqlite:///datasets/database.sqlite')\n",
  4796. "\n",
  4797. "with engine.connect() as conn, conn.begin():\n",
  4798. " data = pd.read_sql_table('final', conn)"
  4799. ]
  4800. },
  4801. {
  4802. "cell_type": "code",
  4803. "execution_count": 25,
  4804. "metadata": {},
  4805. "outputs": [
  4806. {
  4807. "data": {
  4808. "text/html": [
  4809. "<div>\n",
  4810. "<style>\n",
  4811. " .dataframe thead tr:only-child th {\n",
  4812. " text-align: right;\n",
  4813. " }\n",
  4814. "\n",
  4815. " .dataframe thead th {\n",
  4816. " text-align: left;\n",
  4817. " }\n",
  4818. "\n",
  4819. " .dataframe tbody tr th {\n",
  4820. " vertical-align: top;\n",
  4821. " }\n",
  4822. "</style>\n",
  4823. "<table border=\"1\" class=\"dataframe\">\n",
  4824. " <thead>\n",
  4825. " <tr style=\"text-align: right;\">\n",
  4826. " <th></th>\n",
  4827. " <th>game_id</th>\n",
  4828. " <th>clue_id</th>\n",
  4829. " <th>value</th>\n",
  4830. " <th>category</th>\n",
  4831. " <th>clue</th>\n",
  4832. " <th>strike1</th>\n",
  4833. " <th>strike2</th>\n",
  4834. " <th>strike3</th>\n",
  4835. " <th>answer</th>\n",
  4836. " </tr>\n",
  4837. " </thead>\n",
  4838. " <tbody>\n",
  4839. " <tr>\n",
  4840. " <th>0</th>\n",
  4841. " <td>280</td>\n",
  4842. " <td>16720</td>\n",
  4843. " <td>100</td>\n",
  4844. " <td>HIGH ROLLERS</td>\n",
  4845. " <td>After an 1891 roulette run, Charles Wells was ...</td>\n",
  4846. " <td>What is Atlantic City?</td>\n",
  4847. " <td>What is Las Vegas?</td>\n",
  4848. " <td>What is Monaco?</td>\n",
  4849. " <td>Monte Carlo</td>\n",
  4850. " </tr>\n",
  4851. " <tr>\n",
  4852. " <th>1</th>\n",
  4853. " <td>429</td>\n",
  4854. " <td>25403</td>\n",
  4855. " <td>100</td>\n",
  4856. " <td>OH, CRAPS!</td>\n",
  4857. " <td>The combo that totals one shy of \"boxcars\"</td>\n",
  4858. " <td>What is 11?</td>\n",
  4859. " <td>What is 10?</td>\n",
  4860. " <td>What is 9?</td>\n",
  4861. " <td>5 &amp; 6</td>\n",
  4862. " </tr>\n",
  4863. " <tr>\n",
  4864. " <th>2</th>\n",
  4865. " <td>866</td>\n",
  4866. " <td>51549</td>\n",
  4867. " <td>100</td>\n",
  4868. " <td>ROCK &amp; POP</td>\n",
  4869. " <td>It was the last decade in which Cher didn't ha...</td>\n",
  4870. " <td>What are the 1980s?</td>\n",
  4871. " <td>What are the 1970s?</td>\n",
  4872. " <td>What are the 1990s?</td>\n",
  4873. " <td>1950s</td>\n",
  4874. " </tr>\n",
  4875. " <tr>\n",
  4876. " <th>3</th>\n",
  4877. " <td>1018</td>\n",
  4878. " <td>60582</td>\n",
  4879. " <td>100</td>\n",
  4880. " <td>LET'S HAVE A BALL</td>\n",
  4881. " <td>Sink it &amp; you've scratched</td>\n",
  4882. " <td>Um...</td>\n",
  4883. " <td>What is the pinball?</td>\n",
  4884. " <td>What is the 8-ball?</td>\n",
  4885. " <td>the cue ball</td>\n",
  4886. " </tr>\n",
  4887. " <tr>\n",
  4888. " <th>4</th>\n",
  4889. " <td>1069</td>\n",
  4890. " <td>63644</td>\n",
  4891. " <td>100</td>\n",
  4892. " <td>WHAT A YEAR!</td>\n",
  4893. " <td>Dewaele won the Tour de France, Coco Chanel wa...</td>\n",
  4894. " <td>What is 1933?</td>\n",
  4895. " <td>What is 1987?</td>\n",
  4896. " <td>What is 1927?</td>\n",
  4897. " <td>1929</td>\n",
  4898. " </tr>\n",
  4899. " <tr>\n",
  4900. " <th>5</th>\n",
  4901. " <td>1473</td>\n",
  4902. " <td>84364</td>\n",
  4903. " <td>100</td>\n",
  4904. " <td>EUROPEAN HISTORY</td>\n",
  4905. " <td>A former Socialist, he formed the anti-Communi...</td>\n",
  4906. " <td>Who was Lenin?</td>\n",
  4907. " <td>Who was Franco?</td>\n",
  4908. " <td>Who was Hitler?</td>\n",
  4909. " <td>Benito Mussolini</td>\n",
  4910. " </tr>\n",
  4911. " <tr>\n",
  4912. " <th>6</th>\n",
  4913. " <td>1635</td>\n",
  4914. " <td>93864</td>\n",
  4915. " <td>100</td>\n",
  4916. " <td>CHRISTIANITY</td>\n",
  4917. " <td>According to tradition, Dismas &amp; Gestas were t...</td>\n",
  4918. " <td>Who are the thieves?</td>\n",
  4919. " <td>What is Cavalry?</td>\n",
  4920. " <td>What is Mt. Olive?</td>\n",
  4921. " <td>Calvary</td>\n",
  4922. " </tr>\n",
  4923. " <tr>\n",
  4924. " <th>7</th>\n",
  4925. " <td>4166</td>\n",
  4926. " <td>242419</td>\n",
  4927. " <td>100</td>\n",
  4928. " <td>NAME THE DECADE</td>\n",
  4929. " <td>Paul Revere &amp; William Dawes warn colonists tha...</td>\n",
  4930. " <td>What is the 16th century?</td>\n",
  4931. " <td>What is the 18th century?</td>\n",
  4932. " <td>What is the 18th century?</td>\n",
  4933. " <td>the 1770s</td>\n",
  4934. " </tr>\n",
  4935. " <tr>\n",
  4936. " <th>8</th>\n",
  4937. " <td>112</td>\n",
  4938. " <td>6679</td>\n",
  4939. " <td>200</td>\n",
  4940. " <td>ODD ALPHABETS</td>\n",
  4941. " <td>In alphabet radio code, \"B\" is Bravo and \"F\" s...</td>\n",
  4942. " <td>What's the Flamingo?</td>\n",
  4943. " <td>What's a Fandango?</td>\n",
  4944. " <td>What's the Flamenco? - you have it written the...</td>\n",
  4945. " <td>Foxtrot</td>\n",
  4946. " </tr>\n",
  4947. " <tr>\n",
  4948. " <th>9</th>\n",
  4949. " <td>354</td>\n",
  4950. " <td>20984</td>\n",
  4951. " <td>200</td>\n",
  4952. " <td>SPORTS</td>\n",
  4953. " <td>A filly becomes a mare at this age</td>\n",
  4954. " <td>What is 3?</td>\n",
  4955. " <td>What is 1?</td>\n",
  4956. " <td>What is 2?</td>\n",
  4957. " <td>4</td>\n",
  4958. " </tr>\n",
  4959. " </tbody>\n",
  4960. "</table>\n",
  4961. "</div>"
  4962. ],
  4963. "text/plain": [
  4964. " game_id clue_id value category \\\n",
  4965. "0 280 16720 100 HIGH ROLLERS \n",
  4966. "1 429 25403 100 OH, CRAPS! \n",
  4967. "2 866 51549 100 ROCK & POP \n",
  4968. "3 1018 60582 100 LET'S HAVE A BALL \n",
  4969. "4 1069 63644 100 WHAT A YEAR! \n",
  4970. "5 1473 84364 100 EUROPEAN HISTORY \n",
  4971. "6 1635 93864 100 CHRISTIANITY \n",
  4972. "7 4166 242419 100 NAME THE DECADE \n",
  4973. "8 112 6679 200 ODD ALPHABETS \n",
  4974. "9 354 20984 200 SPORTS \n",
  4975. "\n",
  4976. " clue \\\n",
  4977. "0 After an 1891 roulette run, Charles Wells was ... \n",
  4978. "1 The combo that totals one shy of \"boxcars\" \n",
  4979. "2 It was the last decade in which Cher didn't ha... \n",
  4980. "3 Sink it & you've scratched \n",
  4981. "4 Dewaele won the Tour de France, Coco Chanel wa... \n",
  4982. "5 A former Socialist, he formed the anti-Communi... \n",
  4983. "6 According to tradition, Dismas & Gestas were t... \n",
  4984. "7 Paul Revere & William Dawes warn colonists tha... \n",
  4985. "8 In alphabet radio code, \"B\" is Bravo and \"F\" s... \n",
  4986. "9 A filly becomes a mare at this age \n",
  4987. "\n",
  4988. " strike1 strike2 \\\n",
  4989. "0 What is Atlantic City? What is Las Vegas? \n",
  4990. "1 What is 11? What is 10? \n",
  4991. "2 What are the 1980s? What are the 1970s? \n",
  4992. "3 Um... What is the pinball? \n",
  4993. "4 What is 1933? What is 1987? \n",
  4994. "5 Who was Lenin? Who was Franco? \n",
  4995. "6 Who are the thieves? What is Cavalry? \n",
  4996. "7 What is the 16th century? What is the 18th century? \n",
  4997. "8 What's the Flamingo? What's a Fandango? \n",
  4998. "9 What is 3? What is 1? \n",
  4999. "\n",
  5000. " strike3 answer \n",
  5001. "0 What is Monaco? Monte Carlo \n",
  5002. "1 What is 9? 5 & 6 \n",
  5003. "2 What are the 1990s? 1950s \n",
  5004. "3 What is the 8-ball? the cue ball \n",
  5005. "4 What is 1927? 1929 \n",
  5006. "5 Who was Hitler? Benito Mussolini \n",
  5007. "6 What is Mt. Olive? Calvary \n",
  5008. "7 What is the 18th century? the 1770s \n",
  5009. "8 What's the Flamenco? - you have it written the... Foxtrot \n",
  5010. "9 What is 2? 4 "
  5011. ]
  5012. },
  5013. "execution_count": 25,
  5014. "metadata": {},
  5015. "output_type": "execute_result"
  5016. }
  5017. ],
  5018. "source": [
  5019. "data[:10]"
  5020. ]
  5021. },
  5022. {
  5023. "cell_type": "markdown",
  5024. "metadata": {},
  5025. "source": [
  5026. "Now say we want to find out the distribution of occupations of players over the years. When we look into the `players` table, we can see we can create a query that allows for us to aggregate these occupations easily. \n",
  5027. "\n",
  5028. "Using [`read_sql_query()`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql_query.html#pandas.read_sql_query) we can get the job done and dump this into a DataFrame."
  5029. ]
  5030. },
  5031. {
  5032. "cell_type": "code",
  5033. "execution_count": 26,
  5034. "metadata": {
  5035. "collapsed": true
  5036. },
  5037. "outputs": [],
  5038. "source": [
  5039. "query = \"\"\"\n",
  5040. " SELECT occupation, count(occupation) as freq FROM players\n",
  5041. " WHERE occupation != ''\n",
  5042. " GROUP BY occupation \n",
  5043. " ORDER BY count(occupation) DESC \n",
  5044. " \"\"\"\n",
  5045. "\n",
  5046. "with engine.connect() as conn, conn.begin():\n",
  5047. " occupation_data = pd.read_sql_query(query, conn)"
  5048. ]
  5049. },
  5050. {
  5051. "cell_type": "code",
  5052. "execution_count": 27,
  5053. "metadata": {},
  5054. "outputs": [
  5055. {
  5056. "data": {
  5057. "text/html": [
  5058. "<div>\n",
  5059. "<style>\n",
  5060. " .dataframe thead tr:only-child th {\n",
  5061. " text-align: right;\n",
  5062. " }\n",
  5063. "\n",
  5064. " .dataframe thead th {\n",
  5065. " text-align: left;\n",
  5066. " }\n",
  5067. "\n",
  5068. " .dataframe tbody tr th {\n",
  5069. " vertical-align: top;\n",
  5070. " }\n",
  5071. "</style>\n",
  5072. "<table border=\"1\" class=\"dataframe\">\n",
  5073. " <thead>\n",
  5074. " <tr style=\"text-align: right;\">\n",
  5075. " <th></th>\n",
  5076. " <th>occupation</th>\n",
  5077. " <th>freq</th>\n",
  5078. " </tr>\n",
  5079. " </thead>\n",
  5080. " <tbody>\n",
  5081. " <tr>\n",
  5082. " <th>0</th>\n",
  5083. " <td>attorney</td>\n",
  5084. " <td>380</td>\n",
  5085. " </tr>\n",
  5086. " <tr>\n",
  5087. " <th>1</th>\n",
  5088. " <td>senior</td>\n",
  5089. " <td>228</td>\n",
  5090. " </tr>\n",
  5091. " <tr>\n",
  5092. " <th>2</th>\n",
  5093. " <td>graduate student</td>\n",
  5094. " <td>212</td>\n",
  5095. " </tr>\n",
  5096. " <tr>\n",
  5097. " <th>3</th>\n",
  5098. " <td>writer</td>\n",
  5099. " <td>176</td>\n",
  5100. " </tr>\n",
  5101. " <tr>\n",
  5102. " <th>4</th>\n",
  5103. " <td>teacher</td>\n",
  5104. " <td>159</td>\n",
  5105. " </tr>\n",
  5106. " <tr>\n",
  5107. " <th>5</th>\n",
  5108. " <td>junior</td>\n",
  5109. " <td>158</td>\n",
  5110. " </tr>\n",
  5111. " <tr>\n",
  5112. " <th>6</th>\n",
  5113. " <td>law student</td>\n",
  5114. " <td>120</td>\n",
  5115. " </tr>\n",
  5116. " <tr>\n",
  5117. " <th>7</th>\n",
  5118. " <td>lawyer</td>\n",
  5119. " <td>112</td>\n",
  5120. " </tr>\n",
  5121. " <tr>\n",
  5122. " <th>8</th>\n",
  5123. " <td>homemaker</td>\n",
  5124. " <td>101</td>\n",
  5125. " </tr>\n",
  5126. " <tr>\n",
  5127. " <th>9</th>\n",
  5128. " <td>actor</td>\n",
  5129. " <td>97</td>\n",
  5130. " </tr>\n",
  5131. " </tbody>\n",
  5132. "</table>\n",
  5133. "</div>"
  5134. ],
  5135. "text/plain": [
  5136. " occupation freq\n",
  5137. "0 attorney 380\n",
  5138. "1 senior 228\n",
  5139. "2 graduate student 212\n",
  5140. "3 writer 176\n",
  5141. "4 teacher 159\n",
  5142. "5 junior 158\n",
  5143. "6 law student 120\n",
  5144. "7 lawyer 112\n",
  5145. "8 homemaker 101\n",
  5146. "9 actor 97"
  5147. ]
  5148. },
  5149. "execution_count": 27,
  5150. "metadata": {},
  5151. "output_type": "execute_result"
  5152. }
  5153. ],
  5154. "source": [
  5155. "occupation_data[:10]"
  5156. ]
  5157. },
  5158. {
  5159. "cell_type": "markdown",
  5160. "metadata": {},
  5161. "source": [
  5162. "If we look closely, we can see that there are many occupations that are the same, but labeled differently. For example, \"attorney\" and \"lawyer\", or the various kinds of \"teachers\". Thus, if we just look at the frequency from above, we might be deceived in thinking that these frequencies are correct for the groupings that make sense at a slightly higher level of granularity than has been captured.\n",
  5163. "\n",
  5164. "So let's do some data munging with Pandas and see how we might group all the \"teachers\" together.\n",
  5165. "\n",
  5166. "To to this we'll need to do a few things:\n",
  5167. "\n",
  5168. "* find all occupations that have `\"teach\"` in them (or `\"teacher\"` if you'd like)\n",
  5169. "* remove all of those from the data frame\n",
  5170. "* add just the aggregate and apply the generic label \"teacher\"\n",
  5171. "* as a bonus, we'll generate the percentages as an additional column\n",
  5172. "\n",
  5173. "Let's get going!\n",
  5174. "\n",
  5175. "We are going to make use of a nice convenience attribution `str` of the `Series` object. It operates much like the `String` object in Python and has a [`contains()`](http://pandas.pydata.org/pandas-docs/stable/api.html#string-handling) method, which will allow us to determine if the substring we're looking for is contained as a substring in any of the values of the Series. These methods are indeed very useful to have!"
  5176. ]
  5177. },
  5178. {
  5179. "cell_type": "code",
  5180. "execution_count": 28,
  5181. "metadata": {
  5182. "collapsed": true
  5183. },
  5184. "outputs": [],
  5185. "source": [
  5186. "freq_all_occupations = occupation_data.freq.sum()\n",
  5187. "\n",
  5188. "combined_teacher_freq = \\\n",
  5189. " occupation_data[\n",
  5190. " occupation_data['occupation']\n",
  5191. " .str.contains('teach')]\\\n",
  5192. " .sum()"
  5193. ]
  5194. },
  5195. {
  5196. "cell_type": "code",
  5197. "execution_count": 29,
  5198. "metadata": {},
  5199. "outputs": [
  5200. {
  5201. "data": {
  5202. "text/plain": [
  5203. "occupation teacherhigh school teacherhigh school English ...\n",
  5204. "freq 830\n",
  5205. "dtype: object"
  5206. ]
  5207. },
  5208. "execution_count": 29,
  5209. "metadata": {},
  5210. "output_type": "execute_result"
  5211. }
  5212. ],
  5213. "source": [
  5214. "combined_teacher_freq"
  5215. ]
  5216. },
  5217. {
  5218. "cell_type": "markdown",
  5219. "metadata": {},
  5220. "source": [
  5221. "Notice the occupation is the concatenation of all those teachers. We want to change that to a single label `\"teacher\"`."
  5222. ]
  5223. },
  5224. {
  5225. "cell_type": "code",
  5226. "execution_count": 30,
  5227. "metadata": {
  5228. "collapsed": true
  5229. },
  5230. "outputs": [],
  5231. "source": [
  5232. "combined_teacher_freq['occupation'] = 'teacher'"
  5233. ]
  5234. },
  5235. {
  5236. "cell_type": "code",
  5237. "execution_count": 31,
  5238. "metadata": {},
  5239. "outputs": [
  5240. {
  5241. "data": {
  5242. "text/plain": [
  5243. "occupation teacher\n",
  5244. "freq 830\n",
  5245. "dtype: object"
  5246. ]
  5247. },
  5248. "execution_count": 31,
  5249. "metadata": {},
  5250. "output_type": "execute_result"
  5251. }
  5252. ],
  5253. "source": [
  5254. "combined_teacher_freq"
  5255. ]
  5256. },
  5257. {
  5258. "cell_type": "markdown",
  5259. "metadata": {},
  5260. "source": [
  5261. "We now need only append the data to our original DataFrame:"
  5262. ]
  5263. },
  5264. {
  5265. "cell_type": "code",
  5266. "execution_count": 32,
  5267. "metadata": {
  5268. "collapsed": true
  5269. },
  5270. "outputs": [],
  5271. "source": [
  5272. "occupation_data = \\\n",
  5273. " occupation_data[\n",
  5274. " ~occupation_data['occupation']\n",
  5275. " .str.contains('teach')] \\\n",
  5276. " .append(combined_teacher_freq, ignore_index=True)"
  5277. ]
  5278. },
  5279. {
  5280. "cell_type": "code",
  5281. "execution_count": 33,
  5282. "metadata": {},
  5283. "outputs": [
  5284. {
  5285. "data": {
  5286. "text/html": [
  5287. "<div>\n",
  5288. "<style>\n",
  5289. " .dataframe thead tr:only-child th {\n",
  5290. " text-align: right;\n",
  5291. " }\n",
  5292. "\n",
  5293. " .dataframe thead th {\n",
  5294. " text-align: left;\n",
  5295. " }\n",
  5296. "\n",
  5297. " .dataframe tbody tr th {\n",
  5298. " vertical-align: top;\n",
  5299. " }\n",
  5300. "</style>\n",
  5301. "<table border=\"1\" class=\"dataframe\">\n",
  5302. " <thead>\n",
  5303. " <tr style=\"text-align: right;\">\n",
  5304. " <th></th>\n",
  5305. " <th>occupation</th>\n",
  5306. " <th>freq</th>\n",
  5307. " </tr>\n",
  5308. " </thead>\n",
  5309. " <tbody>\n",
  5310. " <tr>\n",
  5311. " <th>4205</th>\n",
  5312. " <td>writer for an online magazine</td>\n",
  5313. " <td>1</td>\n",
  5314. " </tr>\n",
  5315. " <tr>\n",
  5316. " <th>4206</th>\n",
  5317. " <td>writer's assistant</td>\n",
  5318. " <td>1</td>\n",
  5319. " </tr>\n",
  5320. " <tr>\n",
  5321. " <th>4207</th>\n",
  5322. " <td>writer-producer</td>\n",
  5323. " <td>1</td>\n",
  5324. " </tr>\n",
  5325. " <tr>\n",
  5326. " <th>4208</th>\n",
  5327. " <td>writing instructor</td>\n",
  5328. " <td>1</td>\n",
  5329. " </tr>\n",
  5330. " <tr>\n",
  5331. " <th>4209</th>\n",
  5332. " <td>yoga instructor</td>\n",
  5333. " <td>1</td>\n",
  5334. " </tr>\n",
  5335. " <tr>\n",
  5336. " <th>4210</th>\n",
  5337. " <td>yogurt franchise operator</td>\n",
  5338. " <td>1</td>\n",
  5339. " </tr>\n",
  5340. " <tr>\n",
  5341. " <th>4211</th>\n",
  5342. " <td>youth ministry consultant</td>\n",
  5343. " <td>1</td>\n",
  5344. " </tr>\n",
  5345. " <tr>\n",
  5346. " <th>4212</th>\n",
  5347. " <td>zoo docent</td>\n",
  5348. " <td>1</td>\n",
  5349. " </tr>\n",
  5350. " <tr>\n",
  5351. " <th>4213</th>\n",
  5352. " <td>zoo educator</td>\n",
  5353. " <td>1</td>\n",
  5354. " </tr>\n",
  5355. " <tr>\n",
  5356. " <th>4214</th>\n",
  5357. " <td>teacher</td>\n",
  5358. " <td>830</td>\n",
  5359. " </tr>\n",
  5360. " </tbody>\n",
  5361. "</table>\n",
  5362. "</div>"
  5363. ],
  5364. "text/plain": [
  5365. " occupation freq\n",
  5366. "4205 writer for an online magazine 1\n",
  5367. "4206 writer's assistant 1\n",
  5368. "4207 writer-producer 1\n",
  5369. "4208 writing instructor 1\n",
  5370. "4209 yoga instructor 1\n",
  5371. "4210 yogurt franchise operator 1\n",
  5372. "4211 youth ministry consultant 1\n",
  5373. "4212 zoo docent 1\n",
  5374. "4213 zoo educator 1\n",
  5375. "4214 teacher 830"
  5376. ]
  5377. },
  5378. "execution_count": 33,
  5379. "metadata": {},
  5380. "output_type": "execute_result"
  5381. }
  5382. ],
  5383. "source": [
  5384. "occupation_data[-10:]"
  5385. ]
  5386. },
  5387. {
  5388. "cell_type": "markdown",
  5389. "metadata": {},
  5390. "source": [
  5391. "Now let's add the percentage column and call it `pct`:"
  5392. ]
  5393. },
  5394. {
  5395. "cell_type": "code",
  5396. "execution_count": 34,
  5397. "metadata": {
  5398. "collapsed": true
  5399. },
  5400. "outputs": [],
  5401. "source": [
  5402. "occupation_data['pct'] = occupation_data['freq']/occupation_data.freq.sum()"
  5403. ]
  5404. },
  5405. {
  5406. "cell_type": "code",
  5407. "execution_count": 35,
  5408. "metadata": {},
  5409. "outputs": [
  5410. {
  5411. "data": {
  5412. "text/html": [
  5413. "<div>\n",
  5414. "<style>\n",
  5415. " .dataframe thead tr:only-child th {\n",
  5416. " text-align: right;\n",
  5417. " }\n",
  5418. "\n",
  5419. " .dataframe thead th {\n",
  5420. " text-align: left;\n",
  5421. " }\n",
  5422. "\n",
  5423. " .dataframe tbody tr th {\n",
  5424. " vertical-align: top;\n",
  5425. " }\n",
  5426. "</style>\n",
  5427. "<table border=\"1\" class=\"dataframe\">\n",
  5428. " <thead>\n",
  5429. " <tr style=\"text-align: right;\">\n",
  5430. " <th></th>\n",
  5431. " <th>occupation</th>\n",
  5432. " <th>freq</th>\n",
  5433. " <th>pct</th>\n",
  5434. " </tr>\n",
  5435. " </thead>\n",
  5436. " <tbody>\n",
  5437. " <tr>\n",
  5438. " <th>4214</th>\n",
  5439. " <td>teacher</td>\n",
  5440. " <td>830</td>\n",
  5441. " <td>0.078905</td>\n",
  5442. " </tr>\n",
  5443. " <tr>\n",
  5444. " <th>0</th>\n",
  5445. " <td>attorney</td>\n",
  5446. " <td>380</td>\n",
  5447. " <td>0.036125</td>\n",
  5448. " </tr>\n",
  5449. " <tr>\n",
  5450. " <th>1</th>\n",
  5451. " <td>senior</td>\n",
  5452. " <td>228</td>\n",
  5453. " <td>0.021675</td>\n",
  5454. " </tr>\n",
  5455. " <tr>\n",
  5456. " <th>2</th>\n",
  5457. " <td>graduate student</td>\n",
  5458. " <td>212</td>\n",
  5459. " <td>0.020154</td>\n",
  5460. " </tr>\n",
  5461. " <tr>\n",
  5462. " <th>3</th>\n",
  5463. " <td>writer</td>\n",
  5464. " <td>176</td>\n",
  5465. " <td>0.016732</td>\n",
  5466. " </tr>\n",
  5467. " <tr>\n",
  5468. " <th>4</th>\n",
  5469. " <td>junior</td>\n",
  5470. " <td>158</td>\n",
  5471. " <td>0.015020</td>\n",
  5472. " </tr>\n",
  5473. " <tr>\n",
  5474. " <th>5</th>\n",
  5475. " <td>law student</td>\n",
  5476. " <td>120</td>\n",
  5477. " <td>0.011408</td>\n",
  5478. " </tr>\n",
  5479. " <tr>\n",
  5480. " <th>6</th>\n",
  5481. " <td>lawyer</td>\n",
  5482. " <td>112</td>\n",
  5483. " <td>0.010647</td>\n",
  5484. " </tr>\n",
  5485. " <tr>\n",
  5486. " <th>7</th>\n",
  5487. " <td>homemaker</td>\n",
  5488. " <td>101</td>\n",
  5489. " <td>0.009602</td>\n",
  5490. " </tr>\n",
  5491. " <tr>\n",
  5492. " <th>8</th>\n",
  5493. " <td>actor</td>\n",
  5494. " <td>97</td>\n",
  5495. " <td>0.009221</td>\n",
  5496. " </tr>\n",
  5497. " </tbody>\n",
  5498. "</table>\n",
  5499. "</div>"
  5500. ],
  5501. "text/plain": [
  5502. " occupation freq pct\n",
  5503. "4214 teacher 830 0.078905\n",
  5504. "0 attorney 380 0.036125\n",
  5505. "1 senior 228 0.021675\n",
  5506. "2 graduate student 212 0.020154\n",
  5507. "3 writer 176 0.016732\n",
  5508. "4 junior 158 0.015020\n",
  5509. "5 law student 120 0.011408\n",
  5510. "6 lawyer 112 0.010647\n",
  5511. "7 homemaker 101 0.009602\n",
  5512. "8 actor 97 0.009221"
  5513. ]
  5514. },
  5515. "execution_count": 35,
  5516. "metadata": {},
  5517. "output_type": "execute_result"
  5518. }
  5519. ],
  5520. "source": [
  5521. "occupation_data.sort_values(by='pct', ascending=False)[:10]"
  5522. ]
  5523. },
  5524. {
  5525. "cell_type": "markdown",
  5526. "metadata": {},
  5527. "source": [
  5528. "You can explore how you might make a more complex filter by looking at [`apply`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html#pandas.DataFrame.apply), [`applymap`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.applymap.html#pandas.DataFrame.applymap) and [`aggregate`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate). &Xi;"
  5529. ]
  5530. }
  5531. ],
  5532. "metadata": {
  5533. "anaconda-cloud": {},
  5534. "kernelspec": {
  5535. "display_name": "Python [default]",
  5536. "language": "python",
  5537. "name": "python3"
  5538. },
  5539. "language_info": {
  5540. "codemirror_mode": {
  5541. "name": "ipython",
  5542. "version": 3
  5543. },
  5544. "file_extension": ".py",
  5545. "mimetype": "text/x-python",
  5546. "name": "python",
  5547. "nbconvert_exporter": "python",
  5548. "pygments_lexer": "ipython3",
  5549. "version": "3.6.1"
  5550. },
  5551. "toc": {
  5552. "colors": {
  5553. "hover_highlight": "#DAA520",
  5554. "navigate_num": "#000000",
  5555. "navigate_text": "#333333",
  5556. "running_highlight": "#FF0000",
  5557. "selected_highlight": "#FFD700",
  5558. "sidebar_border": "#EEEEEE",
  5559. "wrapper_background": "#FFFFFF"
  5560. },
  5561. "moveMenuLeft": true,
  5562. "nav_menu": {
  5563. "height": "160px",
  5564. "width": "251px"
  5565. },
  5566. "navigate_menu": true,
  5567. "number_sections": false,
  5568. "sideBar": true,
  5569. "threshold": 4,
  5570. "toc_cell": true,
  5571. "toc_section_display": "block",
  5572. "toc_window_display": false,
  5573. "widenNotebook": false
  5574. }
  5575. },
  5576. "nbformat": 4,
  5577. "nbformat_minor": 2
  5578. }