USING LIKE inside pandas.query()

0 votes
I have been using Pandas for more than 3 months and I have a fair idea about the dataframes accessing and querying etc.I have got a requirement wherein I wanted to query the dataframe using LIKE keyword (LIKE similar to SQL) in pandas.query().i.e: Am trying to execute pandas.query("column_name LIKE 'abc%'") command but its failing.

I know an alternative approach which is to use str.contains("abc%") but this doesn't meet our requirement.We wanted to execute LIKE inside pandas.query(). How can I do so?
Jul 22, 2019 in Python by ana1504.k
• 7,890 points
2,348 views

1 answer to this question.

0 votes

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

pandas.query('column_name.str.contains("abc")')

You can easily combine this with other conditions:

pandas.query('column_a.str.contains("abc") or column_b.str.contains("xyz") and column_c>100')

answered Jul 22, 2019 by SDeb
• 13,250 points

Related Questions In Python

+2 votes
2 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,400 points
20,721 views
0 votes
1 answer

How to extract or split characters from number strings using Pandas?

You could just simply use a conversion ...READ MORE

answered Sep 18, 2018 in Python by aryya
• 7,370 points
417 views
0 votes
1 answer

How to put a variable inside a String using Python?

In the easiest way, you can create ...READ MORE

answered Nov 23, 2018 in Python by Nymeria
• 3,520 points

edited Dec 12, 2018 by Nymeria 102 views
0 votes
1 answer

Need help using Joins in Pandas using Python

Hi, there is one scenario where the ...READ MORE

answered Jan 24, 2019 in Python by Nymeria
• 3,520 points
84 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8 by MD 392 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8 by Gitika 1,062 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
5,884 views
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,560 points
3,021 views
0 votes
1 answer

Get business days between start and end date using pandas

You can use BDay() to get the ...READ MORE

answered Feb 15, 2019 in Python by SDeb
• 13,250 points
867 views
0 votes
1 answer

comparing strings in Python using "==" or "is"

is is used for identity testing and ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 13,250 points
76 views