联系方式

您当前位置:首页 >> Python编程Python编程

日期:2024-05-11 08:39

Task 3 - Process Amenities


In this task, you MUST use the csv and the json modules to read and manipulate other files being provided to you. We are going to create some more dictionaries for each of the following files:


melbourne_schools.csv contains a CSV formatted list of schools in the city of Melbourne. This file contains many fields but we are only concerned about the following:

school_no, which contains the school number,

school_name, which contains the school name,

school_type, which contains the type of the school (Primary, Secondary, or Pri/Sec which means both),

school_lat, which contains the latitude value of the school,

school_lon, which contains the longitude value of the school.

melbourne_medical.csv contains a CSV formatted list of GPs in Melbourne. This file contains a few fields but we are only concerned about the following:

gp_code; which contains the code of the GP service,

gp_name; which contains the name of the GP service,

location; which contains the latitude and longitude of the service in a particular format. You should read the file (either manually or through code) to figure out how to read and process the latitude and longitude.

sport_facilities.csv  contains a CSV formatted list of sport facilities in Melbourne. This file contains a few fields but we are only concerned about the following:

facility_id; which contains the ID of the sports facility,

facility_name; which contains the name of the sports facility,

sport_lat; which contains the latitude value of the sports facility,

sport_lon; which contains the longitude value of the sports facility,

sport_played; which contains the sport played at the facility.

Your task is to complete the functionality of the two functions given to you:


process_schools(file_name: str) -> dict: this function should read the file passed as file_name and return a dictionary that contains all the schools read from the file where the key is a string version of the school_no and the value is a dictionary containing five keys (and their appropriate value data types) (school_no <str>,school_name <str>, school_type <str>, school_lat <float> and school_lon <float>).

process_medicals(file_name: str) -> dict: this function should read the file passed as file_name and return a dictionary that contains all the GPs read from the file where the key is the gp_code and the value is a dictionary containing four keys (and their appropriate value data types) (gp_code <str>, gp_name <str>, gp_lat <float>, gp_lon <float>).

process_sport(file_name: str) -> dict: this function should read the file passed as file_name and return a dictionary that contains all the sport facilities read from the file where the key is the facility_id and the value is a dictionary containing five keys (and their appropriate value data types) (facility_id <str>, facility_name <str>, sport_lat <float>, sport_lon <float>, sport_played <str>).

Sample files have been provided to you in this task and can be used to test your code.


You will notice that there are some rows where the location  or latitude or longitude is empty, or marked 'NA'. In these cases, you are supposed to ignore those rows and move on to the next row.


Sometimes you will see some junk characters being read such as '\ufeff' in your file. If this is the case, when you use the appropriate function from the csv module, make sure to mention the encoding as 'utf-8-sig' and that should get rid of the junk characters.


You have also been given some code in the main block which should run if you have completed the three functions properly.



gp_code,gp_name,Address,Phone,location

mgp0001,Brunswick Community Medical Centre,11 Glenlyon Road  Brunswick VIC 3056,03 9231 1260,"{""lat"":-37.771508, ""lng"":144.962631}"

mgp0002,Brunswick Sable Pharmacy,362-366 Sydney Road  Brunswick VIC 3056,03 5998 3771,"{""lat"":-37.7694104, ""lng"":144.9619028}"

mgp0003,Melbourne Paediatric Specialists,Level 4 Suite 403  48 Flemington Road  Parkville VIC 3052,03 9948 5005,"{""lat"":-37.7945021, ""lng"":144.9496536}"

mgp0004,MOONEE VALLEY CITY COUNCIL,Moonee Valley City Council Civic Centre  Floor First  9 Kellaway Avenue  Moonee Ponds VIC 3039,03 9243 8888,"{""lat"":-37.7645702, ""lng"":144.9233013}"

mgp0005,HealthSmart Pharmacy VCCC,Victorian Comprehensive Cancer Centre  311 Grattan Street  Melbourne VIC 3000,03 9349 1067,"{""lat"":-37.7995735, ""lng"":144.9550822}"

mgp0006,City of Melbourne - Family Services Team,Family Services at Carlton Baths  248 Rathdowne Street  Carlton VIC 3053,03 9340 1422,"{""lat"":-37.8040123, ""lng"":144.9692993}"

mgp0007,Chemist Warehouse - Moonee Ponds,88-92 Puckle Street  Moonee Ponds VIC 3039,03 9375 4300,"{""lat"":-37.76670824736842, ""lng"":144.92184127894737}"

mgp0008,Moreland General Practice,80 Moreland Road  Brunswick VIC 3056,03 9385 1250,"{""lat"":-37.7561047, ""lng"":144.9699562}"

mgp0009,Chemist Warehouse - North Melbourne,19-23 Errol Street  North Melbourne VIC 3051,03 9329 0849,"{""lat"":-37.8030195, ""lng"":144.9497312}"

mgp0010,Ascot Vale Pharmacy,67-69 Union Road  Ascot Vale VIC 3032,03 9370 4146,"{""lat"":-37.7805224, ""lng"":144.9147598}"

mgp0011,Clifton Hill Pharmacy,340 Queens Parade  Clifton Hill VIC 3068,03 9489 8731,"{""lat"":-37.7896979, ""lng"":144.9886126}"

mgp0012,TLC Primary Care - Clifton Hill,217-241 Queens Parade  Fitzroy North VIC 3068,03 8638 9200,NA

mgp0013,Essendon Family Medical Clinic,Suite 1  143 Napier Street  Essendon VIC 3040,03 9370 0890,"{""lat"":-37.7497833, ""lng"":144.9187056}"

mgp0014,Clinicare - Fitzroy,165 Smith Street  Fitzroy VIC 3065,03 9417 3377,"{""lat"":-37.8043398, ""lng"":144.9831751}"

mgp0015,Doctors of Northcote,293-295 High Street  Northcote VIC 3070,03 8481 3600,"{""lat"":-37.7774439, ""lng"":144.9974244}"

mgp0016,Moreland City Council - Civic Centre,Coburg Civic Centre  90 Bell Street  Coburg VIC 3058,03 9240 1111,"{""lat"":-37.7414091, ""lng"":144.9693696}"

mgp0017,Priceline Pharmacy Bourke Street Mall,Centrepoint Building  Shop 108-125  283 Bourke Street  Melbourne VIC 3000,03 9654 2034,"{""lat"":-37.813969, ""lng"":144.964876}"

mgp0018,Melbourne City Council,Administration Building  120 Swanston Street  Melbourne VIC 3000,03 9658 9658,"{""lat"":-37.8186502, ""lng"":144.9680827}"

mgp0019,Midtown Medical Clinic,Level 4  250 Collins Street  Melbourne VIC 3000,03 9650 4284,"{""lat"":-37.81549390977831, ""lng"":144.9658734305359}"

mgp0020,Northcote Discount Chemist,Shop 4  Northcote Plaza  Shop 5  3 Separation Street  Northcote VIC 3070,03 9481 7255,"{""lat"":-37.7698296, ""lng"":145.0031884}"

mgp0021,Young People's Health Service (Royal Childrens Hospital),Frontyard Youth Services  244 Flinders Street  Melbourne VIC 3000,03 9611 2409,"{""lat"":-37.817536, ""lng"":144.9662107}"

mgp0022,Pyman's Pharmacy,84 Wellington Parade  East Melbourne VIC 3002,03 9419 4464,"{""lat"":-37.8164145, ""lng"":144.9871973}"

mgp0023,Chemist Warehouse Southbank,Shop 2-3  153-159 Sturt Street  Southbank VIC 3006,03 9682 2278,"{""lat"":-37.8276939, ""lng"":144.9665201}"

mgp0024,Bridge Road Pharmacy,Shop 1  246 Bridge Road  Richmond VIC 3121,03 9429 7337,"{""lat"":-37.8186634, ""lng"":144.9989191}"

mgp0025,Chemist Warehouse - Footscray,190 Barkly Street  Footscray VIC 3011,03 9687 0275,"{""lat"":-37.799424, ""lng"":144.897812}"

mgp0026,Yarra City Council Aged Care Services,333 Bridge Road  Richmond VIC 3121,03 9205 5555,"{""lat"":-37.8184016, ""lng"":145.0008009447552}"

mgp0027,Darebin Immunisation Service,Maternal and Child Health Building  270 Gower Street  Preston VIC 3072,03 8470 8562,"{""lat"":-37.7403819, ""lng"":145.0052003}"

mgp0028,Thornbury Medical Centre,408 Station Street  Thornbury VIC 3071,03 9480 4000,"{""lat"":-37.7548006, ""lng"":145.0205315}"

mgp0029,Buckley Street Pharmacy,Buckley Street Pharmacy  357 Buckley Street  Aberfeldie VIC 3040,393310000,"{""lat"":-37.7554358, ""lng"":144.9027885}"

mgp0030,Chemist Warehouse - Preston,475-479 High Street  Preston VIC 3072,03 9470 6626,"{""lat"":-37.745241, ""lng"":145.002801}"

mgp0031,Priceline Pharmacy Highpoint,Highpoint Shopping Centre  Level 2 Shop 2539  200 Rosamond Road  Maribyrnong VIC 3032,03 9318 2983,"{""lat"":-37.7732838, ""lng"":144.88880200099536}"

mgp0032,Port Phillip City Council - South Melbourne Office,208 220 Bank Street  South Melbourne VIC 3205,03 9209 6777,"{""lat"":-37.8346756, ""lng"":144.9599595}"

mgp0033,Terrywhite Chemmart - Richmond,210 Swan Street  Richmond VIC 3121,03 9428 5143,"{""lat"":-37.8256154, ""lng"":144.9966142}"

mgp0034,Skin Temple,Ground floor  31 Arnold Street  Melbourne VIC 3004,398672992,"{""lat"":-37.8354782, ""lng"":144.9765947}"

mgp0035,Port Phillip City Council - Port Melbourne Office,Bubup Womindjeka Family and Childrens Centre  85 Liardet Street  Port Melbourne VIC 3207,03 9209 6777,"{""lat"":-37.8409829, ""lng"":144.9465618}"

mgp0036,Port Bay Street Pharmacy,51 Bay Street  Port Melbourne VIC 3207,03 9646 3597,"{""lat"":-37.8325082, ""lng"":144.9479193}"

mgp0037,Chemist Warehouse Niddrie,Shop 2-4  312-318 Keilor Road  Niddrie VIC 3042,03 9379 1455,"{""lat"":-37.7307276, ""lng"":144.8738551}"

mgp0038,Chemist Warehouse Preston Home Co DC,Tenancy T08  85 Chifley Drive  Preston VIC 3072,03 9470 2656,"{""lat"":-37.7445036, ""lng"":145.029344}"

mgp0039,First Point Medicals - Niddrie,Ground Floor  Shop 2  326 Keilor Road  Niddrie VIC 3042,03 8383 2351,"{""lat"":-37.737036, ""lng"":144.892353}"

mgp0040,Niddrie Pharmacy Superstore,451-453 Keilor Road  Niddrie VIC 3042,03 9379 2494,"{""lat"":-37.7307276, ""lng"":144.8738551}"

mgp0041,Carnovale Pharmacy,149 Somerville Road  Yarraville VIC 3013,03 9314 7557,"{""lat"":-37.8137128, ""lng"":144.8917186}"

mgp0042,Nelson's Amcal Pharmacy,124 West Street  Glenroy VIC 3046,03 9306 8196,"{""lat"":-37.7049821, ""lng"":144.9387072}"

mgp0043,Inner West Medical Centre,304 Williamstown Road  Yarraville VIC 3013,03 9314 6877,"{""lat"":-37.8254097, ""lng"":144.88092}"

mgp0044,Direct Chemist Outlet Reservoir,4 Edwardes Street  Reservoir VIC 3073,03 9462 1423,"{""lat"":-37.7162353, ""lng"":145.0057433}"

mgp0045,Your Community Health - East Reservoir,125 Blake Street  Reservoir VIC 3073,03 8470 1111,"{""lat"":-37.7310502, ""lng"":145.0286231}"

mgp0046,TerryWhite Chemmart Hawthorn,736-738 Glenferrie Road  Hawthorn VIC 3122,03 9818 1313,"{""lat"":-37.8253913, ""lng"":145.0348377}"

mgp0047,Priceline Pharmacy - Prahran,299-301 Chapel Street  Prahran VIC 3181,03 9510 4253,"{""lat"":-37.8456383, ""lng"":144.994398}"

mgp0048,Amcal Pharmacy - Prahran,181 Chapel Street  Prahran VIC 3181,03 9525 0303,"{""lat"":-37.8456383, ""lng"":144.994398}"

mgp0049,Stott's Corner Pharmacy,532 Glenferrie Road  Hawthorn VIC 3122,03 9818 4424,"{""lat"":-37.8253913, ""lng"":145.0348377}"










facility_id,lga_name,facility_name,sport_lat,sport_lon,sport_played

BRIMBA8346,Brimbank City Council,Dempster Park,-37.775225,144.837725,Cricket

BANYUL12804,Banyule City Council,Central Park,-37.715628,145.105598,Cricket

GREATE11073,Geelong City Council,Highton Reserve,-38.172014,144.321539,Lawn Bowls

WHITTL9525,Whittlesea City Council,Epping Recreation Reserve,-37.639162,145.02391,Australian Rules Football

PYRENE11083,Pyrenees Shire Council,Landsborough & District Bowling Club,-37.008863,143.133602,Lawn Bowls

WODONG11109,Wodonga City Council,Wodonga Sports & Leisure Centre (YMCA),-36.127759,146.861798,Fitness / Gymnasium Workouts

MOORAB11075,Moorabool Shire Council,Bacchus Marsh Civic Community Hub,-37.652767,144.424393,Australian Rules Football

SURFCO11864,Surf Coast Shire Council,Bob Pettit Reserve,-38.348348,144.294279,Australian Rules Football

GOLDEN8282,Golden Plains Shire Council,Bannockburn Golf Club,-38.043618,144.131918,Golf

KNOXCI8586,Knox City Council,Knox Leisureworks YMCA,-37.85695,145.278334,Swimming

MELBOU11024,Melbourne City Council,Punt rd Recreation Reserve & Community Pool,-37.822304,144.987903,Australian Rules Football

WODONG11090,Wodonga City Council,Birallee Park,-36.127132,146.858085,Australian Rules Football

WARRNA11705,Warrnambool City Council ,Bushfield Recreation Reserve,-38.32603,142.506814,Netball

MONASH12001,Monash City Council ,Meade Reserve,-37.922689,145.1162,Australian Rules Football

MOONEE9355,Moonee Valley City Council,Clifton Park,-37.755988,144.891501,Tennis (Outdoor)

GLENEL11562,Glenelg Shire Council,Dartmoor Recreation Reserve,-37.924998,141.273237,Netball

WANGAR11512,Wangaratta Rural City Council,Glenrowan Recreation Reserve,-36.465536,146.215269,Australian Rules Football

WESTWI9510,West Wimmera Shire Council,Kaniva Sport Complex,-36.383359,141.245901,Table Tennis

DAREBI11848,Darebin City Council,Thornbury Bowls Club,-37.758906,144.998573,Lawn Bowls

WELLIN11012,Wellington Shire Council,Loch Sport Recreation Reserve,-38.057079,147.565283,Netball

COLACO11264,Colac Otway Shire Council,Alvie Recreation Reserve,-38.242638,143.50924,Cricket

MANNIN10995,Manningham City Council,Definition Fitness Centre,-37.776105,145.165123,Fitness / Gymnasium Workouts

MURRIN11012,Murrindindi Shire Council,Spring Valley Recreation Reserve ,-37.291851,145.299709,Tennis (Outdoor)

GREATE8699,Bendigo City Council,Marong Golf Course,-36.739011,144.1288,Golf

HUMECI11765,Hume City Council,Jacana Reserve ,-37.682641,144.9044,Cricket

BENALL11082,Benalla Rural City Council,Goorambat Recreation Reserve,-36.407432,145.917106,Australian Rules Football

CAMPAS8805,Campaspe Shire Council,Lockington Recreation Reserve,-36.265744,144.541312,Tennis (Outdoor)

SWANHI9462,Swan Hill Rural City Council,Manangatang Recreation Reserve,-35.055373,142.885338,Cricket

GEELON11182,Geelong City Council,Geelong Pistol Club,-38.238961,144.316561,Shooting Sports

MELTON9052,Melton Shire Council,Burnside Heights Recreation Reserve,-37.736311,144.754676,Cricket

CARDIN11023,Cardinia Shire Council,Lang Lang Showgrounds Reserve,-38.268214,145.560478,Cricket

BRIMBA5637,Brimbank City Council,Keilor Park Recreation Reserve,-37.715205,144.848751,Crickes

MORELA13002,Moreland City Council,CB Smith Reserve,-37.704697,144.969038,Soccer

BAYSID5413,Bayside City Council,Boss James Reserve,-37.9426,145.0218,Netball

BALLAR12515,Ballarat City Council,Mount Xavier Golf Course,-37.562836,143.903691,Golf

SOUTHE11413,Southern Grampians Shire Council ,Mitchell Park,-37.754774,142.031503,Cricket

GLENEL11572,Glenelg Shire Council,Heywood Community Complex,-38.138391,141.62712,Squash / Racquetball

MOIRAS12190,Moira Shire Council,Koonoomoo Recreation Reserve,-35.892441,145.576801,Rugby Union

FRANKS11028,Frankston City Council,Eric Bell Reserve,-38.124842,145.147295,Cricket

GLENEI11263,Glen Eira City Council,Ormond Health & Fitness,,,Fitness / Gymnasium Workouts

WHITTL9560,Whittlesea City Council,Thomastown Indoor Sports,-37.688605,145.003372,Beach Volleyball

MOORAB9421,Moorabool Shire Council,Dunnstown Recreation Reserve,-37.587388,143.959959,Tennis (Outdoor)

MELTON9094,Melton Shire Council,West Melton Tennis Courts,-37.682446,144.56389,Tennis (Outdoor)

SOUTHE11396,Southern Grampians Shire Council ,Dunkeld Recreation Reserve,-37.653317,142.337842,Cricket

CASEYC12294,Casey City Council,KM Reedy Recreation Reserve,-38.023132,145.248479,BMX

KNOXCI8553,Knox City Council,Carrington Park Leisure Centre,-37.895309,145.242961,Gymnastics

GLENEI11219,Glen Eira City Council,King George VI Memorial Park,-37.929295,145.059689,Tennis (Outdoor)

MOUNTA12673,Mount Alexander Shire Council,Harcourt Recreation Reserve,-37.004161,144.257137,Cricket

ALPINE10941,Alpine Shire Council ,Myrtleford Indoor Sports Complex,-36.552593,146.725872,Basketball





代码:

def process_schools(file_name: str) -> dict:

   raise NotImplementedError


def process_medicals(file_name: str) -> dict:

   raise NotImplementedError


def process_sport(file_name: str) -> dict:

   raise NotImplementedError


def main():

   school_dict = process_schools('sample_melbourne_schools.csv')

   medical_dict = process_medicals('sample_melbourne_medical.csv')

   sport_dict = process_sport('sample_sport_facilities.csv')


   sample_medical_code = 'mgp0041'

   print(f"There are {len(school_dict)} schools and {len(sport_dict)} sport facilities in our dataset")

   print(f"The location for {medical_dict[sample_medical_code]['gp_name']} is {medical_dict[sample_medical_code]['gp_lat']}, {medical_dict[sample_medical_code]['gp_lon']}")


if __name__ == '__main__':

   main()


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:821613408 微信:horysk8 电子信箱:[email protected]
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:horysk8