In: Computer Science
Instructions:
To extract the population you will find this code useful:
population = list(df_zip.loc[df_zip['zip'] == zip_code]['population'])
To extract the first 3 digits of a zip_code you will find this code useful:
int(str(zip_code)[:3])
#python code
zip_dict = {}
for index,row in df_zip.iterrows():
zip_code = row['zip']
population = df_zip.loc[df_zip['zip'] == zip_code,'population']
if zip_code in zip_dict:
zip_dict[int(str(zip_code)[:3])] =zip_dict[int(str(zip_code)[:3])] + population #[adds if already exists]
else:
zip_dict[int(str(zip_code)[:3])] = population #create new key if not present in dictionary
###Thank You.......