Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

select rows based on a combination of strings without order in strings

If I have the following code:

df_ = df_[df_['summary'].str.contains('slow delivery', na=False)]
df_ = df_['summary']
print(df_)

And the following list:

df_ = ['May be great product, but slow delivery is annoying',
'May be great product, but slow delivery is annoying',
'slow delivery',
'Great product, slow delivery',
'smewhat slow delivery but accurate and wellpackeged. thank you!']

But I want to select all the items in the list that contain a combination of slow and delivery, instead of ‘slow delivery’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How does the above need to be adjusted?

Thanks in advance.

>Solution :

Might as well just make separate masks for both words in this case. If you have a longer list of words, there are better solutions.

df_ = df_[df_['summary'].str.contains('slow') & df_['summary'].str.contains('delivery')]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading