Currently, my table has over 10000000 records, and there is a column named ID, and I want to update column named '3rd_col' with a new value if the ID is in the given list.
I use .loc and here is my code
for _id in given_ids:
df.loc[df.ID == _id, '3rd_col'] = new_value
But the performance of the above code is slow, how can I improve the performance of updating value?
Sorry, here I want to be more specific on my problem, different id has different values to be assigned based on a function and there are about 4 columns to be assigned.
for _id in given_ids:
df.loc[df.ID == _id, '3rd_col'] = return_new_val_1(id)
df.loc[df.ID == _id, '4rd_col'] = return_new_val_2(id)
df.loc[df.ID == _id, '5rd_col'] = return_new_val_3(id)
df.loc[df.ID == _id, '6rd_col'] = return_new_val_4(id)