I have a DataFrame
with 4 columns of which 2 contain string values. I was wondering if there was a way to select rows based on a partial string match against a particular column?
In other words, a function or lambda function that would do something like
re.search(pattern, cell_in_question)
returning a boolean. I am familiar with the syntax of df[df['A'] == "hello world"]
but can't seem to find a way to do the same with a partial string match say 'hello'
.
Would someone be able to point me in the right direction?
I am using pandas 0.14.1 on macos in ipython notebook. I tried the proposed line above:
and got an error:
but it worked perfectly when an "==True" condition was added, like this:
Quick note: if you want to do selection based on a partial string contained in the index, try the following: