df['cluster'] = -1 for clusterIndex, points in tqdm(clusterMembers.items(), total=len(boundaries)): for point in tqdm(points, leave=False): lzRef, sqrtjRRef = point # Find the index of the point in the DataFrame mask = (df['lz_ref'] == lzRef) & (df['sqrtjR_ref'] == sqrtjRRef) df.loc[mask, 'cluster'] = clusterIndex