我相信需要
isin有
booleanindexing:
NaN默认情况下也忽略s行链接新条件:
#changed df2 with no NaN in C columndf2 = pd.Dataframe({'C':[4, 5, 5, 'SSS','FFF','KKK','AAA'], 'D':[np.nan,np.nan,np.nan,1,np.nan,np.nan,np.nan]})print (df2) C D0 4 NaN1 5 NaN2 5 NaN3 SSS 1.04 FFF NaN5 KKK NaN6 AAA NaNdf = df1[~(df1['A'].isin(df2['C']) | (df1['A'].isnull()))]print (df) A B5 DDD NaN
如果没有必要,请省略,
NaN如果
C列中不存在:
df = df1[~df1['A'].isin(df2['C'])]print (df) A B0 NaN NaN1 NaN NaN2 NaN ciao5 DDD NaN
如果
NaN两个列中都存在,则使用第二个解决方案:
(输入
Dataframes来自问题)
df = df1[~df1['A'].isin(df2['C'])]print (df) A B5 DDD NaN
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)