代写Assignment #5 - Data from the Web, Combining Data代写留学生Python程序


Assignment #5 - Data from the Web, Combining Data

Click on this link: https://classroom.github.com/a/zYnA1PBu (https://classroom.github.com/a/zYnA1PBu) to accept this assignment in GitHub classroom. This will create your homework repository. Clone your new repository.

In this homework, you'll:

1. "Screen scrape" data from a website

o   Using  requests and  BeautifulSoup to download and parse html

o   Use  merge to join DataFrames by a key 2. Work with JSON / Use an API

o   Use the  json module with  requests

Part 1 - Combine Course Info with Requirements

ASCII art source(http://www.oocities.org/spunk1111/school.htm), with modifications

Prep

In this part of the assignment, you'll work on parsing html with a library and regular expressions to extract course information data. Additionally, you'll use the  merge function to put together data from two different DataFrames based on key.

1. Download the course schedule for this semester (https://cs.nyu.edu/dynamic/courses/schedule/) by right-clicking and choosing "Save As". Save this in the root of your project repository; give it a short, but descriptive file name.

2. Download the course catalog(https://cs.nyu.edu/dynamic/courses/catalog/) by right-clicking and choosing "Save As". Save this in the root of your project repository; give it a short, but descriptive file name.

3. Make sure to install any modules necessary for working with html

4. Open up the empty notebook,  courses.ipynb to work on this part of the assignment

Instructions

1. Read the course schedule into a DataFrame.

·  the frame should have the following columns:

o   Number-Section: the course number and section number

   Use your discretion to deal with issues encountered here (for example, some issues may include courses listed with two different course numbers!), but document what you've done and give some rationale for your methodology


n    ⚠ you may encounter an invisible space character (a zero width space) in the course number     depending on how you extract the text (view the markup in Chrome's web inspector tools or try printing it out in Python)

   the easiest way to deal with this is to replace it with emtpy string (assuming   s contains the zero width space): s.replace( '\u200b ', ' ')

o   Name: the name of the course

o   Instructor: the name of the professor

   Again, there maybe issues here, such as multiple instructors; use your discretion, but describe what you've done and why

o   Time: the day(s) and time(s) the course meets

o   (once you read in the data, you'll add a couple of rows)

·  this is what a portion of the  DataFrame may look like (note, the courses are from a past semester, though)

·   once you've read in your data, break apart the  Number-Section column into two separate columns:  Number and  Section o    Number is something like  CSCI-UA.0480

o    Section is something like  001

 try to use regular expressions with groups to do this    the  str accessor method to use is  extract

   check out the end of the regex slides(../slides/python/regex.html) or the official pandas docs    (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.extract.html)

·    show:

 info to show the data types and counts  the first 5 rows

 the last 5 rows

 a random sampling of 5 rows

General Workflow and Hints

·  read in the html file ·  parse the html

·  pick out /extract the data

·  it's very useful to use your browser's web inspector tools (right-click on element and inspect to see html and parent, sibling, and child elements

·   ⚠ see this guide on using web inspector tools for chrome (https://developers.google.com/web/tools/chrome- devtools/dom/)

·  note that in the parsing library we cover in the slides …

·    select ,  select_one ,  find , etc. can be called on an element to find elements nested within it  for example, if  my_div is the result of calling  select_one

… and  my_div is  <div><p class="foo">one</p><p>two</p></div>   …you can select elements within  my_div with  my_div.select('p ')

·  if you just want the first nested element    o   you can dot (  . ) the parent element

o   … and use the name of the nested element next

o   for example if,  my_h1 is  <h1><a>foo</a> bar</h1> o    my_h1.a can be used to access the nested  a

·  if a collection of elements is returned, you can index into it with   [] (essentially, a list)

·    getText() ,  .text or   .get_text() returns all of the text within an element (even nested elements!)

·  pay attention to patterns in data (what makes a course number, what element is a course number usually in?)  ·  also helpful to printout elements themselves (without using   .text ) to see what element was actually selected


·  some example markup and parsing code:

<section class='container'> <div class='row'>

<p>Course Name: <a href="cs123.html">CS-123<a/></p>

<p>Alice Ahn</p> </div>

<div class='row'>'

<p>Course Name: <a href="cs456.html">CS-456</a></p> <p>Bob Bernstein</p>

</div>

</container>

# get every element in the section element with class container # that has the class attribute, row

rows = rom.select('section.container .row') for row in rows:

# looping over this selection gives us each div element

# within each div element, find the paragraphs paragraphs = row.select('p')

# show ALL text in first paragraph in current div

print(paragraphs[0].text) # on 1st iteration: Coure Name: CS-123

# dotting an element with a tag name retrieves the # first nested element with that tag name

print(paragraphs[0].a.text) # on 1st iteration: CS-123  print(paragraphs[1].text) # on 1st iteration: Alice Ahn

2. Read the course catalog into a DataFrame.

·  the frame should have the following columns: 

 Number: the course number

 Prereqs: a text description of the prerequisites 

 Points: the number of credits

·  here's example of a  DataFrame. with some course catalog rows (again,the data is from another semester)

·    show:

 info to show the data types and counts  the first 5 rows

 the last 5 rows

o   a random sampling of 5 rows

·  use a similar parsing strategy as above to read in this DataFrame.

3. Put together both DataFrames



·  create a new DataFrame by … .

·  finding a way to show all scheduled classes in the semester along with their points and prereqs ·  only show the following columns, in this order:

o   Number: course number o   Name: course name

o   Instructor: professor's name o   Time: meeting time

o   Prereqs: course prerequisites

o   Points: number of credits ·    hints:

   use pd.merge to do this (../slides/python/pandas-join-combine.html) o    how=left will keep all rows in the first  DataFrame.

4. Conclusion

·  did you spot any anomalies, discrepancies, or unexpected data or relationships between data? ·  if so, in a markdown cell, describe any problem(s) you saw

·  additionally, describe how you might fix them (or if you already fixed them!)

·  lastly, based on the resulting  DataFrame , describe the behavior of  how=left on these particular  DataFrames ·   if you need to see all rows, use  pd.set_option('display.max_rows ', 200)

Part 2 - Using an API

Overview

In this part of the assignment, you'll request data from a server in json format, parse it, and load it into a  DataFrame . Using this DataFrame you'll use aggregations to produce a report.

The data set is composed of films from the Japanese animation film studio, Studio Ghibli (https://en.wikipedia.org/wiki/Studio_Ghibli).

It is being served from a mirror of the data on  linserv1.cims.nyu.edu . Note, however, that the original data is from https://ghibliapi.herokuapp.com/(https://ghibliapi.herokuapp.com/), which is under an MIT License

(https://github.com/janaipakos/ghibliapi/blob/master/LICENSE) . This is mirrored so that we do not overwhelm the original data source with requests.

Instructions

The goal of the assignment is to create a report showing director's names, the number of Ghibli films that the directors was involved

in, and the average rottentomatoes score of the Studio Ghibli films made by that director. The expected output is shown below:

1. Retrieve the data, and examine it.

·  In `films.ipynb', programmatically retrieve one page of json from this URL: http://linserv1.cims.nyu.edu:10000/films?

_page=1(http://linserv1.cims.nyu.edu:10000/films?_page=1)

·  You can use  requests to do this

 you can use the  json module to manually parse the response content


 Or … . use a feature of the  requests module that allows immediate parsing of a json response by calling the  json() method

o   r = requests.get('some.url')

o   d = r.json() # parses json into dictionary! ·  Examine the keys and values of the dictionary

·  In a markdown cell,write out what keys you maybe interested into create the report specified above ·  Try incrementing the last number in the url where page is 1 … do you get different results?

·  In a markdown cell, describe what happens when you modify the url

2. Load the data into a DataFrame

1. Make a request to http://linserv1.cims.nyu.edu:10000/films?_page=1(http://linserv1.cims.nyu.edu:10000/films?_page=1) again, but this time, load the result into a  DataFrame.

2. Continue collecting additional data and addingto the  DataFrame. until there is no more data to retrieve

3. Report

Create a report that shows:

·  the directors' names as the index (Note that the  index.name can be set to get what appears to be a title for the index (../slides/python/pandas-basics.html#62))

·  the average rottentomatoes score (review aggregator website) ·  the number of films directed

·    concat and  groupby maybe helpful

 


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图