how to replace multiple values with one value python

后端 未结 4 1652
臣服心动
臣服心动 2021-01-02 09:11

How can I replace the data \'Beer\',\'Alcohol\',\'Beverage\',\'Drink\' with only \'Drink\'.

         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 10:10

    Try the following approach:

    lst = ['Beer','Alcohol','Beverage','Drink']
    pat = r"\b(?:{})\b".format('|'.join(lst))
    
    df = df.replace(pat, 'Drink', regexp=True)
    

提交回复
热议问题