Python 排除列中包含其他数据帧中的值的行
我有两个数据帧,df1和df2。一个是初始数据帧(从源获得的数据),另一个较小,包含一些数学变换。为简单起见,它们都有以下布局:Python 排除列中包含其他数据帧中的值的行,python,pandas,dataframe,Python,Pandas,Dataframe,我有两个数据帧,df1和df2。一个是初始数据帧(从源获得的数据),另一个较小,包含一些数学变换。为简单起见,它们都有以下布局: df1: A B C 1 apple a 2 pear b 3 banana c 4 berry d 5 coconut e 6 mango f df2: A B C D E 1 apple a AT 14 2 pear
df1:
A B C
1 apple a
2 pear b
3 banana c
4 berry d
5 coconut e
6 mango f
df2:
A B C D E
1 apple a AT 14
2 pear b BT DA
5 coconut e OT OT
6 mango f MA AP
本质上,我需要另一个数据帧,即df_excluded_值,它包含基于A列从df2中排除的行
谢谢 您可以使用
~
和isin()
:
返回行的预期输出,其df1
中的列“A”值在df2的列“A”中不存在:
A B C
2 3 banana c
3 4 berry d
这回答了你的问题吗?
A B C
2 3 banana c
3 4 berry d