Python:创建所需格式的时间序列数据



任何人都可以帮助生成以下格式的Python时间序列数据吗。日期月年小时最小秒。从2020年4月1日至2021年3月31日:2020年04月01日0.00.00至2021年03月31日23:50:00

"时间序列

01/04/2020 0:00:00
01/04/2020 0:10:00
.......
.......

31/03/2021 23:50:00

''

我会使用pandas.date_range作为

import pandas as pd
start = '2020-04-01 00:00:00'
end = '2021-03-31 23:50:00'
time_series = pd.date_range(start, end, freq='10min')
# formatted time series can be achieved via:
fmt = '%d-%m-%y %H:%M:%S'
ts_formatted = [i.strftime(fmt) for i in time_series]

查看中的fmt语法https://strftime.org/,用于所需的时间格式

我认为这段代码可以像您预期的一样工作

from datetime import date, datetime, timedelta
start = datetime(year=2020, month=4, day=1)
end = datetime(year=2021, month=4, day=1)
interval = timedelta(minutes=10)
while(start<end):
print(start.strftime('%d/%m/%Y %H:%M:%S'))
start += interval

最新更新