how to match a word in a datacolumn with a list of values and applying ignorecase in pandas in python

前端 未结 2 1108
太阳男子
太阳男子 2020-12-22 12:02

I have a df,

Name
Ram is one of the key ram
Kumar is playing cricket
Ravi is playing and ravi is a good player

and a list

m         


        
2条回答
  •  暖寄归人
    2020-12-22 12:43

    Is this what you are looking for ?

    new_l = [i.lower() for i in my_list]
    extracted = df['Name'].str.lower().str.findall('(' + '|'.join(new_l) + ')').apply(set)
    
    
    df['Match'] = extracted.apply(','.join)
    df['count'] = extracted.apply(len)
    
                                              Name     Match  count
    0                      Ram is one of the key ram       ram      1
    1                       Kumar is playing cricket                0
    2  Ravi Ram is playing and ravi is a good player  ram,ravi      2
    

提交回复
热议问题