Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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 熊猫:在一列上合并两个数据帧,但只保留不同列的数据_Python_Pandas - Fatal编程技术网

Python 熊猫:在一列上合并两个数据帧,但只保留不同列的数据

Python 熊猫:在一列上合并两个数据帧,但只保留不同列的数据,python,pandas,Python,Pandas,我有两个数据帧:frame1和frame2 In [10]: frame1[:5] Out[10]: cid 0 531 1 1102 2 1103 3 1406 4 1409 In [14]: frame2[:5] Out[14]: cid media_cost imps booked_revenue 0 72692 29.671446 13918 84.961853 1 72704 3121.781201 6992

我有两个数据帧:frame1和frame2

In [10]: frame1[:5]
Out[10]:
    cid
0   531
1  1102
2  1103
3  1406
4  1409

In [14]: frame2[:5]
Out[14]:
     cid   media_cost     imps  booked_revenue
0  72692    29.671446    13918       84.961853
1  72704  3121.781201  6992946     9912.982516
2    531     0.001540        2        0.000000
3  39964  2307.119001  3997167     5425.629736
4  72736    45.716847   143574       56.280000
frame1有60888行,frame2有139846行

使用这两个数据帧,我想创建第三个数据帧,它基本上由frame2组成,所有与frame1共享的cid值都已删除。因此,在本例中,我希望frame3是frame2,没有与frame1共享的第2行cid 531。。

如何:

>>> f1
    cid
0   531
1  1102
2  1103
3  1406
4  1409
>>> f2
     cid   media_cost     imps  booked_revenue
0  72692    29.671446    13918       84.961853
1  72704  3121.781201  6992946     9912.982516
2    531     0.001540        2        0.000000
3  39964  2307.119001  3997167     5425.629736
4  72736    45.716847   143574       56.280000
>>> f2[~f2.cid.isin(f1.cid)]
     cid   media_cost     imps  booked_revenue
0  72692    29.671446    13918       84.961853
1  72704  3121.781201  6992946     9912.982516
3  39964  2307.119001  3997167     5425.629736
4  72736    45.716847   143574       56.280000