I have a dataframe as follows
------------------------------
Name | countries
-----------------------------
Batman | India
Superman | Canada
Spiderman | Australia
Search String - Dictionary :-
keywords = {
Male :
[
{ Maxwell : [ India , US ] } ,
{ George : [ France , Germany , Spain ] }
],
Female :
[
{ Martha : [ Australia ] }
]
}
Problem Statement:-
For each row of the dataframe , I need to search the countries column with the words in the "Dict value " - and wherever there is a match, need to return the first level key and its parent level key
Expected output
-----------------
------------------------------------------------------------------------
Name | countries | level2 | level1
------------------------------------------------------------------------
Batman | India | Maxwell | Male
Superman | Canada | NaN | NaN
Spiderman | Australia | Martha | Female
Comments
Post a Comment