Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 基于Pandas中的条件匹配两个数据帧_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 基于Pandas中的条件匹配两个数据帧

Python 3.x 基于Pandas中的条件匹配两个数据帧,python-3.x,pandas,Python 3.x,Pandas,我有一个Python查询 我有两个数据帧: df1: Process ID,room no,IP Address,port,status 2553,4,192.168.1.9,2,started 2556,4,192.168.1.49,0,started 2556,2,192.168.1.25,25,started 3056,8,192.168.1.49,0,started df2: Process ID,room no,IP Address,port,status 2553,4,1

我有一个Python查询

我有两个数据帧:

 df1:
Process ID,room no,IP Address,port,status
2553,4,192.168.1.9,2,started    
2556,4,192.168.1.49,0,started
2556,2,192.168.1.25,25,started
3056,8,192.168.1.49,0,started

df2:
Process ID,room no,IP Address,port,status
2553,4,192.168.1.9,2,completed
2556,4,192.168.1.49,0,completed
2556,2,192.168.1.25,25,completed
2556,2,192.168.1.46,25,completed
3056,8,192.168.1.49,0,completed
我想根据与df1匹配的条件从df2中删除行

对于每个与df1有多个匹配项的df2行(基于两列值(进程ID、端口)),应该删除df2中具有(相同进程ID和端口)的多余行

希望我的解释可以理解

简言之,修改后的df2应如下所示:

df2:
Process ID,room no,IP Address,port,status
2553,4,192.168.1.9,2,completed
2556,4,192.168.1.49,0,completed
2556,2,192.168.1.25,25,completed
3056,8,192.168.1.49,0,completed

非常感谢您在这方面提供的任何帮助。

我的新df2不等于df1。状态列不同。此示例仅根据
进程ID
端口
df2
中删除重复项。一个更好的例子会有所帮助。
df1
可以有多个具有相同
进程ID
端口的行吗?如果您只想从
df2
中删除重复项,可能
df2。删除重复项([“进程ID”,“端口])
就是您想要的。