熊猫根据 df1 中另一列中的字符串删除 df2 中的行



我有 2 个熊猫数据帧,其中idfirst_seenlast_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

相关内容

最新更新