【发布时间】:2021-07-08 02:50:36
【问题描述】:
我有一个包含 Latitude、Longitude、summedDistance 和 runingDistance 列的数据框。
我使用了下面的代码,它可以工作:
summedDistance = 0
for i in range(0, len(dfLatLong)-1):
fromLocation = (dfLatLong.loc[i, "Latitude"], dfLatLong.loc[i, "Longitude"])
toLocation = (dfLatLong.loc[i+1, "Latitude"], dfLatLong.loc[i+1, "Longitude"])
summedDistance += Helper.fromtoDistance(fromLocation, toLocation)
dfLatLong.loc[i, 'runingDistance'] = Helper.fromtoDistance(fromLocation, toLocation)
dfLatLong.loc[i, 'summedDistance'] = summedDistance
(Helper函数使用纬度和经度的连续行之间的测地线距离)
有没有办法使用 map 或 apply 来消除 For 循环?
谢谢
【问题讨论】:
-
试试 numpy.select()
标签: python dataframe dictionary apply