I have two dataframes, main df and index df.
The target I want to do is let the column
product
of main df can use 'contain' function in index df to filter key word.In the end, the main df can have new a column
keyword
to showmain_df[keyword]=[C2,VA,E220F,7350M]
.
main df is
data num product
0 2019-10-01 39013000 xxxxxC2xxxxxxx
1 2019-10-01 39013000 xxxxxxVAxxxxxxxxxxxx
2 2019-10-28 39013000 xxxxxxxxE220Fxxxxxxxxxxxxx
3 2019-12-31 39013000 xxxxxxxx7350Mxxxxxxxx
index df is
product
0 VA
1 C2
2 7350M
3 E220F
My code is:
for key in key_word:
mask = df_import_tmp0["product"].str.contains(key)
df_import_tmp0['keyword']=key
The output is not what I want:
df_import_tmp0
data num product keyword
0 2019-10-01 39013000 xxxxxC2xxxxxxx E220F
1 2019-10-01 39013000 xxxxxxVAxxxxxxxxxxxx E220F
2 2019-10-28 39013000 xxxxxxxxE220Fxxxxxxxxxxxxx E220F
3 2019-12-31 39013000 xxxxxxxx7350Mxxxxxxxx E220F