Subset pandas DataFrame based on two columns ignoring what order the match happens in
First, some comments on your question-asking: in your initial statement, you talk about matching 'col1' etc., but in your actual code, you have 'from, 'to', 'source', and 'target'. You talk about subsetting, but then you talk about pd.merge(), and those are completely different things. You formatting is poor, resulting your column names not lining up with the actual columns when you show the output in your code. When you generate random sample data, you should set a seed so that people will get the same data, and can check whether their code is doing the same thing as yours. Your test data is poorly chosen. For instance, does row for which 'from' matches one of the to_keep columns have to match the row in which 'to' matches, or can they match different rows? Can they both match the same column (e.g. 'from' and 'to' both match 'target'), or do they have to match different columns.  Neither your test cases nor your problem description are clear on those points; one has to go through your code to figure out what you mean. 

Assuming that they have match on the same row, and in different columns, this code should work:

def check(row):
    forward = (to_keep['source'] == row['from']) &amp; (to_keep['target'] == row['to'])
    reverse = (to_keep['source'] == row['to']) &amp; (to_keep['target'] == row['from'])
    return any(forward) | any(reverse)


kept_df = df_all.loc[[check(row) for row in df_all.iterrows()]]