I need to select the rows that are according to the following line:

Like this is for numbers:


I need this: where the words do are inside the name of a given row

data[data['field'] LIKE '%do%']

and this: where it starts with 01

data[data['field'] LIKE '01%']

I think it needs regex but I don't know how to do it


You can use simple patterns or more advanced regex patterns in the str.contains() method:


For the case where the strings needs to start with a pattern, you can either use a regex pattern in contains (^ denotes the pattern should be at the beginning) or match which defaults to looking for patterns starting from the beginning:

  • Can you tell me also how to do the opposite, to leave out those that start with 01? – user122244 Jun 12 '18 at 14:19
  • You can "invert" a mask selection using~: data[~data['field'].contains(..)] – joris Jun 12 '18 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.