I am trying to write a for loop that loops through a data frame and assigns either 0 or the first three digits of the given zip code depending on the population. My TA says I need to fix the second line to loop through the index rather than the length of the data frame but I am unsure how to move forward. Here's the question and my code.
"In this part, you should write a for loop, updating the df_users dataframe. Go through each user, and update their zip code, to Safe Harbor specifications: If the user is from a zip code for the which the "Geographic Subdivision" is less than equal to 20,000, change the zip code in df_users to '0' (as a string). Otherwise, zip should be only the first 3 numbers of the full zip code. Do all this by directly updating the zip column of the df_users DataFrame."
for item in range(0, len(df_users)):
population = zip_dict[df_zip.loc[item, 'population']]
if population <= 20000:
df_users.loc[item, 'zip'] = '0'
else:
new_zip = (df_users.loc[item, 'zip'])[:3]
df_users.loc[item, 'zip'] = new_zip