Question

Python HW05 Members of the Bay Area Bike Share are able, for a very low cost, to ride bikes between stations all over the San

return contents First, use the readcSV function to read the file trips_20150831.csv and create a set named trips that contain

Here are the data needed for the program.

SanFrancisco.csv

station_id,name,lat,long,dockcount,landmark,installation

41,Clay at Battery,37.795001,-122.39997,15,San Francisco,8/19/2013

42,Davis at Jackson,37.79728,-122.398436,15,San Francisco,8/19/2013

45,Commercial at Montgomery,37.794231,-122.402923,15,San Francisco,8/19/2013

46,Washington at Kearney,37.795425,-122.404767,15,San Francisco,8/19/2013

47,Post at Kearney,37.788975,-122.403452,19,San Francisco,8/19/2013

48,Embarcadero at Vallejo,37.799953,-122.398525,15,San Francisco,8/19/2013

49,Spear at Folsom,37.790302,-122.390637,19,San Francisco,8/20/2013

50,Harry Bridges Plaza (Ferry Building),37.795392,-122.394203,23,San Francisco,8/20/2013

SanJose.csv

station_id,name,lat,long,dockcount,landmark,installation

2,San Jose Diridon Caltrain Station,37.329732,-121.901782,27,San Jose,8/6/2013

3,San Jose Civic Center,37.330698,-121.888979,15,San Jose,8/5/2013

4,Santa Clara at Almaden,37.333988,-121.894902,11,San Jose,8/6/2013

5,Adobe on Almaden,37.331415,-121.8932,19,San Jose,8/5/2013

6,San Pedro Square,37.336721,-121.894074,15,San Jose,8/7/2013

7,Paseo de San Antonio,37.333798,-121.886943,15,San Jose,8/7/2013

8,San Salvador at 1st,37.330165,-121.885831,15,San Jose,8/5/2013

9,Japantown,37.348742,-121.894715,15,San Jose,8/5/2013

10,San Jose City Hall,37.337391,-121.886995,15,San Jose,8/6/2013

11,MLK Library,37.335885,-121.88566,19,San Jose,8/6/2013

12,SJSU 4th at San Carlos,37.332808,-121.883891,19,San Jose,8/7/2013

13,St James Park,37.339301,-121.889937,15,San Jose,8/6/2013

14,Arena Green / SAP Center,37.332692,-121.900084,19,San Jose,8/5/2013

16,SJSU - San Salvador at 9th,37.333955,-121.877349,15,San Jose,8/7/2013

80,Santa Clara County Civic Center,37.352601,-121.905733,15,San Jose,12/31/2013

84,Ryland Park,37.342725,-121.895617,15,San Jose,4/9/2014

trips_20150831.csv

Trip ID,Duration,Start Date,Start Station,Start Terminal,End Date,End Station,End Terminal,Bike #,Subscriber Type,Zip Code

913460,765,8/31/2015 23:26,Harry Bridges Plaza (Ferry Building),50,8/31/2015 23:39,San Francisco Caltrain (Townsend at 4th),70,288,Subscriber,2139

913459,1036,8/31/2015 23:11,San Antonio Shopping Center,31,8/31/2015 23:28,Mountain View City Hall,27,35,Subscriber,95032

913455,307,8/31/2015 23:13,Post at Kearny,47,8/31/2015 23:18,2nd at South Park,64,468,Subscriber,94107

913454,409,8/31/2015 23:10,San Jose City Hall,10,8/31/2015 23:17,San Salvador at 1st,8,68,Subscriber,95113

913453,789,8/31/2015 23:09,Embarcadero at Folsom,51,8/31/2015 23:22,Embarcadero at Sansome,60,487,Customer,9069

Python HW05 Members of the Bay Area Bike Share are able, for a very low cost, to ride bikes between stations all over the San Francisco Bay area. The following files contain data collected from the program. trips_20150831.csv Data for all bike share trips on 08/31/2015 SanFrancisco.csv: Data about the stations in San Francisco . SanJose.csv: Data about the stations in San Jose Below is the function given in class to read a csv file and return its contents as a list of tuples. (Don't worry if you don't understand the particulars. We'll be discussing everything you need to know about functions soon) In [1]: import CSv def readCSV(file): fh data open(file, 'r') # open file for reading # create a csv reader. # contain commas csv . reader(fh , delimiter',' ,quotechar: "') this is needed because some titles contents[] count 0 # create an empty list in which to store the data # process each line of the file # skip the first line which contains column headers for line in data: count += 1 if(count--1): continue lineData tuple(line) contents.append (lineData) # store the data as a tuple (for consistency with the previous example) # add the tuple of data to the topMovies list. return contents
return contents First, use the readcSV function to read the file trips_20150831.csv and create a set named trips that contains all stations that were visited on 08/31/2015. (You can use either Start Station or End Station. Both columns contain the same information.) In I : Now read the file SanFrancisco.csv and create a set named SanFrancisco that contains the names of all of the stations in San Francisco. (names are in the second column of the file) In : Next read the file SanJose.csv and create a set named SanJose that contains the names of all of the stations in San Jose. (names are in the second column of the file) In : Use set operations to create a set called SForSJ that contains all stations that are either in San Francisco or San Jose In : Finally, use set operations to create a set called neither that contains all stations visited that are neither in San Francisco nor San Jose In L J: Upload your completed Jupyter notebook by 11:59pm on Thursday 10/18
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem. Comments are included so that you understand whats going on. Let me know if you have any doubts or if you need anything to change.

Thank You !!
=============================================================================


import csv
def readCSV(file):
    fh=open(file,'r')
    data=csv.reader(fh,delimiter=',',quotechar='"')
    contents=[]
    count=0
    for line in data:
        count+=1
        if (count==1):continue
        lineData=tuple(line)
        contents.append(lineData)
    return contents

contents=readCSV('trips_20150831.csv')
trips=set()
for content in contents:trips.add(content[3])
contents=readCSV('SanFrancisco.csv')
SanFranciso=set()
for content in contents: SanFranciso.add(content[1])
contents=readCSV('SanJose.csv')
SanJose = set()
for content in contents: SanJose.add(content[1])
# using union() function to add the elements into a single set
SForSJ = SanFranciso.union(SanJose)
print('Either in SanFrancisco or San Jose:',SForSJ)
#using difference to find cities in trips but not in union set 
neither=trips.difference(SForSJ)
print('Neither in SanFrancisco or San Jose:',neither)

==================================================================================

contents readcsv(trips 20150831.esv trips set for content in contents:trips. add (content[31) contents-readcsv(SanFrancisCO

Add a comment
Know the answer?
Add Answer to:
Here are the data needed for the program. SanFrancisco.csv station_id,name,lat,long,dockcount,landmark,installation 41,Clay at Battery,37.795001,-122.39997,15,San Francisco,8/19/2013 42,Davis at Jac...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CASE 8 Unlocking the Secrets of the Apple iPhone in the Name of access the male...

    CASE 8 Unlocking the Secrets of the Apple iPhone in the Name of access the male San Bernardino suspect's iPhone 5c. Cook stated: Antiterrorism We are challenging the FBI's demands with the deepes respect for American democracy and a love of our country. We believe it would be in the best interest of everyone to step back and consider the implications While we believe the FBI's intentions are good, if would be wrong for the w e nt to force...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT