我正在努力为数据帧添加缺失的时间戳。
我当前的输出是:
start_Local_round end_Local_round alarmId
2020-09-01 00:30:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 00:30:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:20:00+00:00 2020-09-01 02:30:00+00:00 155698
我需要这样写:
start_Local_round end_Local_round alarmId
2020-09-01 00:30:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 00:30:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 00:40:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 00:40:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 00:50:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 00:50:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:00:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:00:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:10:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:10:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:20:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:20:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:30:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:30:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:40:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:40:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 01:50:00+00:00 2020-09-01 01:50:00+00:00 15568
2020-09-01 01:50:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:00:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:10:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:20:00+00:00 2020-09-01 02:30:00+00:00 155698
2020-09-01 02:20:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:30:00+00:00 2020-09-01 02:30:00+00:00 155698
2020-09-01 02:30:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:40:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 02:50:00+00:00 2020-09-01 02:50:00+00:00 2560
2020-09-01 03:00:00+00:00
2020-09-01 03:10:00+00:00
2020-09-01 03:20:00+00:00
目的是将它与另一个具有时间戳和10分钟数据的数据帧合并
我尝试创建一个包含时间段
所有数据点的数据帧#création des points 10'
def datetime_range(start, end, delta):
current = start
while current < end:
yield current
current += delta
min_date = df.start_Local.min().round('10min')
max_date = df.start_Local.max().round('10min')
dts = [dt.strftime('%Y-%m-%d %H:%M:%S') for dt in datetime_range(min_date, max_date, timedelta(minutes=10))]
但是我不能和我的原始数据合并。
你有什么主意可以帮我吗?
谢谢! !
我猜你可以将第二个数据帧附加到第一个数据帧(pandas. datafframe .append),然后按开始时间
排序df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
df
A B
0 1 2
1 3 4
df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
df.append(df2)
A B
0 1 2
1 3 4
0 5 6
1 7 8
感觉答案是:
new_df = df.set_index('Start').resample("10min").first().reset_index().reindex(columns=df.columns)