如何申请功能point_rotation
功能上Coordinates1
,Coordinates2
列在下面的数据帧:
def point_rotation(point):
"""
Changing axis
"""
xcor, ycor = (700, 0)
xcor1, ycor1 = (0, 0)
xpoint, ypoint = point
xnew = xpoint - xcor
ynew = ypoint - ycor
xnew = xcor1 + math.cos(math.radians(270)) * (xnew - xcor1) - math.sin(math.radians(90)) * (ynew - ycor1)
ynew = ycor1 + math.sin(math.radians(270)) * (xnew - xcor1) + math.cos(math.radians(90)) * (ynew - ycor1)
return round(xnew, 0), round(ynew, 0)
这是我当前的数据框:
df = pd.DataFrame({'X_1': [-34.58, -15.78, -33.45, 4.60, 10.48],
'Y_1': [-58.66, -47.91, -70.66, -74.08, -66.86],
'X_2': [-3.58, -1.8, -3.5, 4.0, 1.48],
'Y_2': [-5.66, -4.1, -7.6, -7.8, -6.86]})
df['Coordinates1'] = list(zip(df.X_1, df.Y_1))
df['Coordinates2'] = list(zip(df.X_2, df.Y_2))
想要的输出:应该有列,Coordinates3
并且Coordinates4
这些列基本上是point_rotation
通过传递列Coordinates1
和Coordinates2
.
我尝试使用该apply
函数,但它抛出了一个错误:too many values to unpack (expected 2)
.
谢谢您的帮助!
如果您使用列表理解。您的新点将是一个元组(类似于您定义Coordinates1
和的方式Coordinates2
)
df['Coordinates3'] = [point_rotation(point) for point in df['Coordinates1']]
apply
似乎也有效:)
df['Coordinates4'] = df['Coordinates2'].apply(point_rotation)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句