我有2个pandas数据帧,其中id
,first_seen
,last_seen
是字符串,days_since_fire
是整数。我想从df1中的id
等于'2020-05-02'的df2中删除last_seen
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
答案 0 :(得分:1)
以您的情况
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