我有3个不同的pandas数据帧,我已连接。现在我想只保留那些出现在三列中的行并删除其余的行。例如
Column1 Column2 Column3
0 John a Sam
1 Sam b Rob
2 Daniel c John
3 Varys d Ella
我希望仅保留Column1
中显示在Column1
和Column2
中的行。在上面的例子中它的ROW-0& 1.
期望的输出
Column1 Column2
0 John a
1 Sam b
答案 0 :(得分:0)
通过将系列'Column3'
作为arg传递给isin
来过滤df以测试成员资格:
In [42]:
df[df['Column1'].isin(df['Column3'])]
Out[42]:
Column1 Column2 Column3
0 John a Sam
1 Sam b Rob