繁体   English   中英

C 应用用户定义的 function 到 pandas dataframe 特定列并将新列添加到 Z6A8064B53DF47945555707

[英]apply user defined function to pandas dataframe specific columns and add new columns to dataframe

我创建了一个名为polar(X_relative, Y_relative, Z_relative)的 function,它采用如图所示的这 3 个 arguments,结果是新的 arguments,它们是(azimuth_angle, tilt_angle) I want to apply this function to a pandas dataframe where the function arguments are certain columns in the dataframe and would like to add the output arguments of the functions (azimuth_angle, tilt_angle) as new coulmns in the dataframe where the function is calculated for each row .

dataframe columns: X , Y, Z , X_relative , Y_relative , Z_relative
dataframe coulmns I expect after applying the function: X , Y, Z , X_relative , Y_relative , Z_relative , azimuth_angle , tilt_angle

polar的回归包装成一个系列:

return pd.Series([azimuth_angle, tilt_angle]) 

然后使用apply

df[['azimuth_angle', 'tilt_angle']] = df.apply(lambda x: polar(x.X_relative, x.Y_relative, x.Z_relative), axis = 1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM