如何匹配列表和大熊猫

时间:2020-01-07 12:35:15

标签: python-3.x pandas dataframe

我有一个名为myList = []的列表。 我想将此列表的零索引中的那些与数据帧pd的[“ numbers”]臂进行比较。我想将与列表不同的内容分开。

例如:

myList=["20","30","40","31","41"]
pd["numbers"] = ["20","30","40","41","31",**"50"**]

1 个答案:

答案 0 :(得分:1)

使用set

例如:

myList=["20","30","40","31","41"]
df = pd.DataFrame({"numbers": ["20","30","40","41","31","50"]})
print(set(df['numbers']) - set(myList))
# --> {'50'}