pandas isin

在已知id索引的情况下,如何获取所需要的行呢?已经不止一次遇到这样的情况,经历过重重筛选,所得到的最终结果是一串满足所有条件的id列表。

pandas 的isin 能很好的解决这个问题,

import pandas as pd


a = [1,2,4]
b = pd.DataFrame([[1,2],
                 [2,4],
                 [3,4]],index=[1,2,3],columns=["A","B"])
b["A"].isin(a)
1     True
2     True
3    False
Name: A, dtype: bool


# 取反
~b["A"].isin(a)
1    False
2    False
3     True
Name: A, dtype: bool
原文地址:https://www.cnblogs.com/zenan/p/9983597.html