[Python] Multiple substring search and all should be present in dataframe

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of strings , that I want to search in a particular column in a dataframe. I want to output the rows which has ALL of those values.

    I have used the code below:

    kw = ['apple','banana','kiwi']
    regex_val = "|".join(kw)

    df['col'].str.contains(regex_val)


    This gives the output of any of the keywords is present. I want to output when ALL are present for a record.

    Also the keywords list is not limited to 3. It can vary based on user input.

    I have tried the str.contains , but it works if any of the keywords are present.

    Continue reading...

Compartilhe esta Página