last_month = df['month'].max() excl = df[df['month']==last_month]['ID'].values df[df.apply(lambda r: not r['ID'] in excl,axis=1)]