我有 2 个熊猫数据帧,其中id
、first_seen
、last_seen
是字符串,days_since_fire
是整数。 我想从 df2 中删除 df1 中的last_seen
等于'2020-05-02'的id
df1
id first_seen last_seen days_since_fire
0 001 2020-05-01 2020-05-01 0
1 002 2020-05-01 2020-05-01 0
2 003 2020-05-02 2020-05-02 0
df2
id
0 001
1 003
2 002
3 004
期望的结果:
df2
id
0 001
2 002
3 004
在您的情况下
df2=df2.loc[~df2.id.isin(df1.loc[df1.last_seen=='2020-05-02','id'])].copy()
df2
Out[393]:
id
0 1
2 2
3 4