losers = list(df['agent'][df['deal_stage']=='Lost']) # this makes a list of values in the agent column, based off of if the value in 'deal_stage' is lost
df = df[~df['agent'].isin(losers)] # this returns all columns, but filtered to where the 'agent' column only has values that are not in the losers list
当您运行已有的代码时,您将遍历每一行,并根据
dead_stage
列值决定是否保留该行。正如您所说,这将显示值为其他值的行。如果我理解正确的话,你是在试图过滤掉曾经输过的经纪人——因此,如果经纪人赢过也输过,我们还想删除赢过的那一行您可以通过制作一个
losers
列表,然后在该列表上过滤您的数据帧,这些数据帧将是曾经丢失过的人的名字来实现这一点相关问题 更多 >
编程相关推荐