I want to compare one column with another column in the same dataframe. Not just between adjacent value but iterating through every value in Col1 and see if it exists in Col2 values.
Col1 Col2 exists
cat pig true
a cat false
pig b true
mat axe false
Thanks.
Col1_value = set(df['Col1'].unique())
df['exists'] = df['Col2'].map(lambda x : True if x in Col1_value else False)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.