I have two dataframes.
df = pd.DataFrame([['klf1', 10], ['sp2', 3], ['klf3', 12], ['egr1', 5], ['klf11', 2]], columns=['tf','count'])
df2 = pd.DataFrame([['Homer-sp2', 0.01], ['Homer-klf1', 0.0001], ['Homer-klf3-chip', 0.05], ['klf11',0.002], ['Homer-egr1', 0.01]], columns=['Motif_name','p_val'])
I'm trying to merge them using df['tf'] content.
For exemple 'klf1' row should be 'klf1' 10 0.0001
So I have to use the content of df['tf'] as pattern matching in df2[Motif_name]
I'm expecting to get this df
df_final=pd.DataFrame([['Klf1', 10,0.0001], ['sp2', 3, 0.01], ['klf3', 12,0.05], ['egr1', 5,0.01], ['klf11', 2,0.002]], columns=['tf','count','p_val'])
I tried to use .str.contains('pattern') but it works only for one pattern. Here I don't know how can I loop on the content of the column tf.
df2['Motif_name'].str.contains(df['tf'].str.lower())
Also .str.contains will look for pattern and I know that I'll have a problem on klf1 VS klf11 because klf1 is in klf11. How can I manage this problem?