So I want to use the isin() method with df.query() to select the rows with id in the list: id_list . Similar questions were asked before, but they used the typical df[df['id'].isin(id_list)] . I am wondering if there is a way to use df.query() .
df = pd.DataFrame({'a': list('aabbccddeeff'), 'b': list('aaaabbbbcccc'), 'c': np.random.randint(5, size=12), 'd': np.random.randint(9, size=12)}) id_list = ["a", "b", "c"]
And it gives an error
df.query('a == id_list')
source share