How to apply a function to two columns of Pandas dataframe

前端 未结 12 1314
名媛妹妹
名媛妹妹 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:36

    My example to your questions:

    def get_sublist(row, col1, col2):
        return mylist[row[col1]:row[col2]+1]
    df.apply(get_sublist, axis=1, col1='col_1', col2='col_2')
    

提交回复
热议问题