Changing the value of a column based on the condition on another column I have a table whose header looks like this:
    complaint_type  borough street_name incident_zip    latitude    longitude

I want to check if the "incident_zip" column of each row is in a specific list of zip codes and change the "borough" accordingly. There is a large amount of data and i cannot find any better code to do this. I am using python 3.6.
There is a way that is not optimum for performance, but clear to read and understand. Also, you can use more complex logic and update with different values as you wish.

def myfunc(row):
    if row['incident_zip'] in [this is a list of zip codes]:
        return new_value
    else:
        return row['borough'] #return old value

data['borough'] = data.apply(myfunc, axis=1)


If your logic of update is quite simple, then you can do it like that

mask = df['incident_zip'].isin([this is a list of zip codes])
df[mask]['borough'] = new_value