Combine pandas DataFrame query() method with isin()

后端 未结 3 1949
礼貌的吻别
礼貌的吻别 2020-12-14 07:53

So I want to use isin() method with df.query(), to select rows with id in a list: id_list. Similar question was asked bef

3条回答
  •  情话喂你
    2020-12-14 08:30

    You can also include the list within the query string:

    >>> df.query('a in ["a", "b", "c"]')
    

    This is the same as:

    >>> df.query('a in @id_list')
    

提交回复
热议问题