0

I have a df with list of keywords and its corresponding columns

   Column 1         Column2  Column3 
    Processing        Test     CPI
    WCR               Key      Comp
    DD|FF         Interp   Set ( If both keywords are present then 
                                     select this row)

Folder path : C:\WCR basic\testing\dual, it should match with column1 WCR row value and return value of column2 and column3. Output : Key, Comp

When i loop through the list of filepath, if file path contains any of the keyword present in column1 then it should retrun the values from column2 and 3. I am not sure if using regex in this situation would give better result?

1 Answer 1

1

IIUC, you might have an easier time using a list comprehension, and searching whether each value of Column 1 is a substring of your folder path:

folder_path = 'C:\\WCR basic\\testing\\dual'

>>> df.loc[[i in folder_path for i in df['Column 1']], ['Column2','Column3']]
  Column2 Column3
1     Key    Comp
Sign up to request clarification or add additional context in comments.

1 Comment

I want to use regular expression to handle a scenario to check 2 keywords and if both keywords are present then select the row, I used df.loc[[ any(re.findall(i, folder_path, re.IGNORECASE)) for i in df['column1']], ["column2","column3]] . in this case regex works as OR condition how to change it to AND to ensure both words are present?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.