[英]How to find the length of non-exclusive data in Pandas DataFrame
尋找 DataFrame 中非獨占數據的總長度
df1:
ID
0 7878aa
1 6565dd
2 9899ad
3 4158hf
4 4568fb
5 6877gh
df2:
ID
0 4568fb <-is in df1
1 9899ad <-is in df1
2 6877gh <-is in df1
3 9874ad <-not in df1
4 8745ag <-not in df1
所需的輸出:
2
我的代碼:
len(df1['ID'].isin(df2['ID'] == False)
我的代碼最終顯示了 DataFrame 的總長度為 6。如何找到非獨占行的總長度?
謝謝!
使用isin
和否定然后sum
(~df2['ID'].isin(df1['ID'])).sum()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.