Deal with carriage return while filtering rows of pandas dataframe with str.contains and AND operation

I would like to filter my dataframe on the rows whose "Libelle" string column contains every element in a specific list of strings.

I found some great information about how to filter on rows that contains the intersection of string variables in a list (see here ).

The solution is to use the following regex

df[df['Libelle'].str.contains(r'(?=.*word1)(?=.*word2)...((?=.*word3)', case = False, regex = True)

Now I am facing an issue. It works except for the the lines where there is a carriage return.

So I tried in vain the following regex :




I do not know if this could help : the dataframe contains data loaded from an excel file.

Does any one has faced a similar problem ? Any help is welcome !! Many Thanks !

Read more here:

Content Attribution

This content was originally published by Etienne Numérogliss Drt at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: