马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 澍梵. 于 2020-4-5 20:05 编辑
源文件数据:
id time jd wd
0 1 2018-12-27 10:46:24 118.8196860 32.3586430
1 1 2018-12-27 10:48:57 118.8257510 32.3325110
2 1 2018-12-27 10:49:02 118.8254230 32.3306620
3 1 2018-12-27 10:49:07 118.8275570 32.3325600
4 1 2018-12-27 10:54:40 118.7770990 32.2727000
源代码:from math import sin, cos, asin, sqrt
import numpy as np
import pandas as pd
import datetime
data = pd.read_excel('userdata_1.xlsx')
def GetDistance(jdA, wdA, jdB, wdB):
# jdA,wdA,jdB,wdB = map(radians, [float(jdA), float(wdA), float(jdB), float(wdB)]) # 经纬度转换成弧度
dlon = jdB - jdA
dlat = wdB - wdA
a = sin(dlat / 2) ** 2 + cos(wdA) * cos(wdB) * sin(dlon / 2) ** 2
distance = 2 * asin(sqrt(a)) * 6371 * 1000 # 地球平均半径,6371km
distance = round(distance / 1000, 3)
return distance
# 借助多点金纬度求其中心点
def ComputeMeanCoord(data, start, end):
jd = data.loc[start:end, 'jd']
wd = data.loc[start:end, 'wd']
x = np.mean(jd)
y = np.mean(wd)
return (x, y)
# 获取停留点的函数,,data为dataframe对象,距离门限单位为米,时间门限单位为秒
if __name__ == "__main__":
data = pd.read_excel('userdata_1.xlsx')
# distThreh,timeThreh=map(eval,input("距离跨度(用空格隔开),时间距(以分钟为单位):").split())
# StayPoint_Detection(data,distThreh,timeThreh)
SP = StayPoint_Detection(data,15,60)
print('停留点数目=', len(SP))
print(SP)
错误显示:
[/code]
datetime中有个函数可以将字符串转为可读类型的date
datetime.datetime.strptime('2017-3-22 15:25:32','%Y-%m-%d %H:%M:%S')
可以将你所读到的字符串转为date,然后就能用date的各种函数了
|