您好我有一个巨大的数据框架与以下列结构交替:
distanceA, angleA, distanceB, angleB, distanceC, angleC ....
现在我想从这个数据框中获取两个新列。对于每一行,我想获得最小距离,然后对于特定距离我也想知道该最小距离处的角度(即如果距离B是该行中的最小距离,那么我想要提取距离B和angleB,即使angleB可能不是最小角度)到目前为止我的代码是:
# since distances are only every other column:
distances = df_sf.iloc[:, ::2]
# find minimum distance in each row:
df_sf['min_dist']=distances.min(axis=1, skipna=True)
# find the column of minimum distance:
df_sf['min_dist_loc']=distances.idxmin(axis=1,skipna=True)
# add one to the column number, since the angle is one to the right:
df_sf['angle_of_min_dist_loc']=df_sf.apply(lambda row:row['min_dist_loc']+1, axis=1)
现在,我得到了位置,但是如何将角度(直到最小距离单元格)复制到一个新的单独列中?
非常感谢帮助。 :)