繁体   English   中英

如何在 Pandas DataFrame 中查找非独占数据的长度

[英]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.

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