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 in Python by ana1504.k
• 7,870 points
18 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 by SDeb
• 13,160 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,320 points
4,708 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 ariaholic
• 7,320 points
65 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,500 points

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

How to rename columns in pandas (Python)?

It is easy by just adding ".columns" ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
86 views
0 votes
1 answer

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

The major difference is size includes NaN ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
674 views
0 votes
2 answers
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,550 points
1,139 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 in Python by SDeb
• 13,160 points
176 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,160 points
29 views