日期MALAN51CMBM972380 MALAN51CMBM972380 MALPC813MLM018007 MALPC813MLM018007
使用:
idx = df['repm_ro_dtime'].sub(df['Dates']).dt.days.abs().groupby(df['epm_vin']).idxmin()
df = df.loc[idx].assign(date_flag = 'Yes')
print (df)
epm_vin repm_milg repm_ro_dtime complaints_flag date_flag
1 MALAN51CMBM972380 25845 2021-08-06 Yes Yes
3 MALPC813MLM018007 28795 2021-03-05 Yes Yes
Dates
1 2021-08-07
3 2020-10-01