I have large pandas dataframe (around million rows) and a list of id-s (length of array is 100,000). For each id in df1 I have to check if that id is in my list (called special
) and flag it accordingly:
df['Segment'] = df['ID'].apply(lambda x: 1 if x in special else np.nan)
problem is that this is extremely slow, as for million id-s lambda expression checks if that id is in a list of 100,000 entries. Is there a faster way to accomplish this?