简体   繁体   中英

Pandas- Comparing two columns with different indexes and different length

I want to compare these two columns. When I used isin(), it operates with index, so even though four values are in common, it only returns one True.

在此处输入图像描述

How may I tackle this?

Many thanks,

IIUC use:

df['new'] = df['id'].isin(df['authorid'])

If not working checj if same types, if numeric or strings are same in both columns:

print (df.dtypes)

Then try eg convert to strings:

df['new'] = df['id'].astype(str).isin(df['authorid'].astype(str))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM