Question: Need help with code in python given a data frame called df_zip which has zip and population columns as pictured print (df_zip) zip population 01001

Need help with code in python given a data frame called df_zip which has zip and population columns as pictured
 Need help with code in python given a data frame called
df_zip which has zip and population columns as pictured print (df_zip) zip

print (df_zip) zip population 01001 01002 01003 01005 01007 01008 01009 01010 01011 01012 01013 01020 01022 0 16769 29049 10372 5079 4 14649 1263 6 7 8 9 741 3609 1370 661 10 23188 29668 2451 12 13 14 01026 01027 01028 01029 0103O 946 1 7660 15720 15 1 6 17 789 11669 3e) Sort zipcodes into "Geographic Subdivision" The Safe Harbour Method applies to "Geographic Subdivisions" as opposed to each zipcode itself. Geographic Subdivision: All areas which share the first 3 digits of a zip code Count the total population for each geographic subdivision Warning: you have to be savy with a dictionary here To understand how a dictionary works, check the section materials, use google and go to discussion sections! Instructions: Create an empty dictionary: zip dict Loop through all the zip_codes in df zip Create a dictionary key for the first 3 digits of a zip_code in zip_dict Continually add population counts to the key that contains the same first 3 digits of the zip code To extract the population you will find this code useful iist (df-zip. loc [df-zipl.zip zip-codel [population " 1) "" population " To extract the first 3 digits of a zip_code you will find this code useful: int (str (zip code) 1:3]) Note: this code may take some time (many seconds, up to a minute or two) to run print (df_zip) zip population 01001 01002 01003 01005 01007 01008 01009 01010 01011 01012 01013 01020 01022 0 16769 29049 10372 5079 4 14649 1263 6 7 8 9 741 3609 1370 661 10 23188 29668 2451 12 13 14 01026 01027 01028 01029 0103O 946 1 7660 15720 15 1 6 17 789 11669 3e) Sort zipcodes into "Geographic Subdivision" The Safe Harbour Method applies to "Geographic Subdivisions" as opposed to each zipcode itself. Geographic Subdivision: All areas which share the first 3 digits of a zip code Count the total population for each geographic subdivision Warning: you have to be savy with a dictionary here To understand how a dictionary works, check the section materials, use google and go to discussion sections! Instructions: Create an empty dictionary: zip dict Loop through all the zip_codes in df zip Create a dictionary key for the first 3 digits of a zip_code in zip_dict Continually add population counts to the key that contains the same first 3 digits of the zip code To extract the population you will find this code useful iist (df-zip. loc [df-zipl.zip zip-codel [population " 1) "" population " To extract the first 3 digits of a zip_code you will find this code useful: int (str (zip code) 1:3]) Note: this code may take some time (many seconds, up to a minute or two) to run

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!