我有一个包含3列和milion行的pandas DataFrame:
time longitude latitude
1 x1 y1
2 x2 y2
3 x3 y3
...
我想应用一个函数来根据经度和纬度计算距离。基本上我需要一种表达函数的方法可以处理数据帧中的两个相邻行 喜欢
compute_distance(x1,y1,x2,y2)
我知道有一些方法可以沿轴1和0应用函数,但它们似乎只适用于单行或列。如何表达涉及多行或多列的内容。
答案 0 :(得分:0)
申请将无法执行此操作,但您可以执行以下操作:
def compute_distance(df):
next_df = df.shift(-1)
return distance_on_unit_sphere(df["lat"], df["long"],
next_df["lat"], next_df["long"]):
从这里开始 http://www.johndcook.com/python_longitude_latitude.html