Hi I have two DataFrames like below
DF1 Alpha | Numeric | Special and | 1 | @ or | 2 | # lol ok | 4 | & DF2 with single column Content boy or girl school @ morn pyc LoL ok student Chandra I want to search if anyone of the column in DF1 has anyone of the keyword in content column of DF2 and the output should be in a new DF
`df11 = (df1.unstack() .reset_index(level=2,drop=True) .rename_axis(('col_order','col_name')) .dropna() .reset_index(name='val_low')) df22 = (df2['Content'].str.split(expand=True) .stack() .rename('val') .reset_index(level=1,drop=True) .rename_axis('idx') .reset_index())` df22['val_low'] = df22['val'].str.lower() df = (pd.merge(df22, df11, on='val_low', how='left') .dropna(subset=['col_name']) .sort_values(['idx','col_order']) .drop_duplicates(['idx'])) df = (pd.concat([df2, df.set_index('idx')], axis=1) .fillna({'col_name':'Other'})[['val','col_name','Content']]) but it is not considering the spaces between lol ok
expected_output_DF val col_name Content 0 or Alpha boy or girl 1 @ Special school @ morn 2 lol ok Alpha pyc LoL ok student 3 NaN Other Chandra someone help me with this