本文介绍了查找不在pandas数据框数据中的列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表和熊猫数据框数据,看起来像这样:

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        19'
30        58
32        48

我尝试在列表中找不到user_id列表.我想要的结果是

I've try to find user_id list not in list.My desired result is

result = [15, 40, 45, 50]

获得预期结果的最简单方法是什么?(当前,我已经通过for〜loop得到了结果)

What is the easiest way to get desired result?(Currently I've got the result by for~loop)

谢谢.

推荐答案

使用设置操作:

list(set(user_id)-set(df.user_id))
Out[84]: [40, 50, 45, 15]

这篇关于查找不在pandas数据框数据中的列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:32
查看更多