Find the list values not in pandas dataframe data

前端 未结 3 2016
刺人心
刺人心 2021-01-26 09:08

I have a list and pandas dataframe data that looks like this:

user_id = [10, 15, 20, 25, 30, 32, 40, 45, 50]

user_id  value 
10        45 
20        49 
25             


        
3条回答
  •  孤城傲影
    2021-01-26 10:01

    You can just use Series.isin() with negation (~).

    df[~df["user_id"].isin(set(user_id))]

    Conversion to set is always preferable as you'll better running time.

提交回复
热议问题