试图将观察到的时间四舍五入到最近的一小时
Example Data:
observed_time = ['2020-02-20T17:54:00Z', '2020-02-20T18:54:00Z']
slice_begin_time=['2020-02-20T17:50:00Z', '2020-02-20T18:50:00Z', '2020-02-20T19:50:00Z', '2020-02-20T20:50:00Z', '2020-02-20T21:50:00Z']
slice_end_time=['2020-02-20T18:05:00Z', '2020-02-20T19:05:00Z', '2020-02-20T20:05:00Z', '2020-02-20T21:05:00Z', '2020-02-20T22:05:00Z']
### LIBS
from datetime import datetime, timedelta
import pandas as pd
s = pd.Series(pd.to_datetime(observed_time))
for i in range(len(slice_begin_time)):
s[s.between(pd.Timestamp(slice_begin_time[i]),pd.Timestamp(slice_end_time[i]))] == s.round(freq = 'H')
print(s)
我得到了错误:round()得到了一个意外的关键字参数'freq'
我确实想把它连成一个系列
希望这有助于:
输出:
如果您只是想将时间序列转换为最近的小时,您可以使用:
相关问题 更多 >
编程相关推荐