其實有兩個問題,但我們試着解釋一下。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