其实有两个问题,但我们试着解释一下。Python,Pandas:在时间戳和偏移量上加入数据帧
我有两个数据源(例如数据框)。一个包含GPS坐标和从动轨道的时间戳。另一个包含特定的兴趣点,由时间偏移给出 - 但没有GPS坐标。任务是找到兴趣点的GPS坐标。
这就是我得到的。与GPS数据帧坐标重采样为1秒的时间间隔和缺失值以线性的方式内插:
df_resampled.head()
有了这个输出:
Time, LongitudeDegrees, LatitudeDegrees, DistanceMeters, AltitudeMeters
2017-08-24 13:33:46, 15.457636, 47.047332, 0.0, 348.600006
2017-08-24 13:33:47, 15.457668, 47.047288, 0.0, 348.600006
2017-08-24 13:33:48, 15.457699, 47.047244, 0.0, 348.600006
2017-08-24 13:33:49, 15.457973, 47.047136, 0.0, 348.600006
备注:的类型都是浮动而索引是Numpy.dtype(日期时间)。
# convert numeric types first
df = df.apply(pd.to_numeric, errors='ignore')
# convert timestamp to datetime and set the index
df['Time'] = pd.to_datetime(df['Time'])
df.set_index('Time', inplace=True)
# resample to seconds and linear fill of missing values
df_downscaled = df.resample('S').mean()
df_resampled = df_downscaled.interpolate(method='linear')
其他数据帧中包含的兴趣点,并没有时间戳,但时间上错开:转换和重采样被做
df_poi.head()
给这个输出:
index, time_offset, value
0, 00:25, 60
1, 01:18, 60
2, 01:30, 100
3, 01:55, 100
4, 02:16, 100
问题&任务:但现在我卡住了。我正在考虑将第二个数据帧的time_offset列转换为句点或日期时间类型,并将其添加到第一个数据帧的第一个时间戳(start_time)。
但一)我不知道怎么的格式毫米字符串转换:SS(分钟:秒),日期时间偏移(或期间),并把它添加到另一个时间戳。
到所有偏移具有待添加的START_TIME,会是这样:
start_time = df_resampled.index[0]
一旦被转换成真实时间戳偏移,我将加入第二数据帧上的时间戳列中的第一个。
我使用了str.split,并将时间从分钟和秒转换为秒。然后我添加了偏移量的start_time。尽管你的解决方案更聪明。 – Matthias