且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从python DataFrame中的lambda函数的多个返回值创建多个列

更新时间:2023-11-21 21:05:28

一种方法是将返回值包装在 pd.Series 中以便分配

One way would be to wrap the return value in pd.Series in order to assign to new dataframe columns.

g = lambda x: pd.Series(f_polyfit(x.y1, x.y2, x.y3, x.y5, x.y5, degree=1))
df[['slope', 'R2']] = df.apply(g, axis=1)