我认为您需要:
import pandas as pddf = pd.Dataframe({'A':[1,2,3], 'B':[4,5,6]})print (df) A B0 1 41 2 52 3 6def myfunction(B, A): #some staff result = B + A # do something here to get the result return resultdf['C'] = df.apply(lambda x: myfunction(x.B, x.A), axis=1)print (df) A B C0 1 4 51 2 5 72 3 6 9
要么:
def myfunction(x): result = x.B + x.A # do something here to get the result return resultdf['C'] = df.apply(myfunction, axis=1)print (df) A B C0 1 4 51 2 5 72 3 6 9
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)