【发布时间】:2019-03-13 15:36:15
【问题描述】:
如何在以下数据框中的 Coordinates1、Coordinates2 列上应用函数 point_rotation 函数:
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,它们基本上是通过传递列 Coordinates1 和 Coordinates2 从 point_rotation 函数派生的。
我尝试使用apply 函数,但它给我一个错误:too many values to unpack (expected 2)。
感谢您的帮助!
【问题讨论】:
-
嗨。什么是
height_units。似乎缺少定义。 -
我的错。更新了
标签: python pandas function dataframe apply