I want to get all the rows in df
whose path
column contains a substring new+ folder
. This question Select by partial string from a pandas DataFrame and the answer by cs95 has been very helpful for substrings like new+
or fol
but the results are not correct when I search
new+ folder
.
>>>dft = pandas.DataFrame([[ '/new+folder/'], ['/new+ folder/']], columns=['a'])
index path
0 `/new+folder/`
1 `/new+ folder/`
Now testing with query
>>>print(dft.query('a.str.contains("new+")', engine='python').head())
a
0 new+folder
1 new+ folder
print(dft.query('a.str.contains("new+ ")', engine='python').head())
Empty DataFrame
Columns: [a]
Index: []
>>>print(dft.query('a.str.contains("new+ f")', engine='python').head())
Empty DataFrame
Columns: [a]
Index: []
Testing with contains
:
>>>dft[dft['a'].str.contains('new+')]
a
0 new+folder
1 new+ folder
>>>dft[dft['a'].str.contains('new+ ')]
a
>>>dft[dft['a'].str.contains('new+ f')]
a
How can I get the error resolved that comes when there is a after a
+
or I feel special characters?
Pandas 0.24.2 Python 3.7.3 64-bit