1

My Input Dataframe is:

list_of_dicts1 = {"Filter":["abc",'def']}

test1 = pd.DataFrame(list_of_dicts1)

list_of_dicts2 = {"C":["a",'z']}

test2 = pd.DataFrame(list_of_dicts2)

Output Desired is

list_of_dicts3 = {"Filter":['abc']}

test3 = pd.DataFrame(list_of_dicts3)

How can I filter dataframe test1 based on "C" column of test2 dataframe using pandas

1 Answer 1

1

Use Series.str.contains with join by | for regex or:

df = test1[test1['Filter'].str.contains('|'.join(test2['C']))]
print (df)
  Filter
0    abc
Sign up to request clarification or add additional context in comments.

Comments

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.