How to apply a function to two columns of Pandas dataframe

前端 未结 12 1183
名媛妹妹
名媛妹妹 2020-11-22 06:17

Suppose I have a df which has columns of \'ID\', \'col_1\', \'col_2\'. And I define a function :

f = lambda x, y : my_function_expres

12条回答
  •  一向
    一向 (楼主)
    2020-11-22 06:46

    A simple solution is:

    df['col_3'] = df[['col_1','col_2']].apply(lambda x: f(*x), axis=1)
    

提交回复
热议问题