USING LIKE inside pandas.query()

后端 未结 6 581
庸人自扰
庸人自扰 2020-12-13 18:22

I have been using Pandas for more than 3 months and I have an fair idea about the dataframes accessing and querying etc.

I have got an requirement wherein I wanted t

6条回答
  •  旧巷少年郎
    2020-12-13 18:42

    If you have to use df.query(), the correct syntax is:

    df.query('column_name.str.contains("abc")', engine='python')
    

    You can easily combine this with other conditions:

    df.query('column_a.str.contains("abc") or column_b.str.contains("xyz") and column_c>100', engine='python')
    

    It is not a full equivalent of SQL Like, however, but can be useful nevertheless.

提交回复
热议问题