pandas生成指定间隔的连续时间列表
import pandas as pd
print(pd.date_range("2020-12-09 10:26:01","2020-12-09 10:26:15",freq='S'))
print(pd.date_range("2020-12-09 10:26:01","2020-12-09 10:26:15",freq='10S'))
print(pd.date_range("2020-12-09 10:22:01","2020-12-09 10:26:02",freq='Min'))
print(pd.date_range("2020-12-09 10:22:01","2020-12-09 15:26:02",freq='H'))
print(pd.date_range("2020-12-09 10:22:01","2020-12-15 10:26:02",freq='D'))
print(pd.date_range("2020-12-09 10:22:01","2020-12-31 10:26:02",freq='W'))
print(pd.date_range("2020-01-09 10:22:01","2020-12-09 10:26:02",freq='M'))
print(pd.date_range("2020-12-09 10:22:01","2030-12-09 10:26:02",freq='Y'))
result:
DatetimeIndex(['2020-12-09 10:26:01', '2020-12-09 10:26:02',
'2020-12-09 10:26:03', '2020-12-09 10:26:04',
'2020-12-09 10:26:05', '2020-12-09 10:26:06',
'2020-12-09 10:26:07', '2020-12-09 10:26:08',
'2020-12-09 10:26:09', '2020-12-09 10:26:10',
'2020-12-09 10:26:11', '2020-12-09 10:26:12',
'2020-12-09 10:26:13', '2020-12-09 10:26:14',
'2020-12-09 10:26:15'],
dtype='datetime64[ns]', freq='S')
DatetimeIndex(['2020-12-09 10:22:01', '2020-12-09 10:23:01',
'2020-12-09 10:24:01', '2020-12-09 10:25:01',
'2020-12-09 10:26:01'],
dtype='datetime64[ns]', freq='T')
DatetimeIndex(['2020-12-09 10:22:01', '2020-12-09 11:22:01',
'2020-12-09 12:22:01', '2020-12-09 13:22:01',
'2020-12-09 14:22:01', '2020-12-09 15:22:01'],
dtype='datetime64[ns]', freq='H')
DatetimeIndex(['2020-12-09 10:22:01', '2020-12-10 10:22:01',
'2020-12-11 10:22:01', '2020-12-12 10:22:01',
'2020-12-13 10:22:01', '2020-12-14 10:22:01',
'2020-12-15 10:22:01'],
dtype='datetime64[ns]', freq='D')
DatetimeIndex(['2020-12-13 10:22:01', '2020-12-20 10:22:01',
'2020-12-27 10:22:01'],
dtype='datetime64[ns]', freq='W-SUN')
DatetimeIndex(['2020-01-31 10:22:01', '2020-02-29 10:22:01',
'2020-03-31 10:22:01', '2020-04-30 10:22:01',
'2020-05-31 10:22:01', '2020-06-30 10:22:01',
'2020-07-31 10:22:01', '2020-08-31 10:22:01',
'2020-09-30 10:22:01', '2020-10-31 10:22:01',
'2020-11-30 10:22:01'],
dtype='datetime64[ns]', freq='M')
DatetimeIndex(['2020-12-31 10:22:01', '2021-12-31 10:22:01',
'2022-12-31 10:22:01', '2023-12-31 10:22:01',
'2024-12-31 10:22:01', '2025-12-31 10:22:01',
'2026-12-31 10:22:01', '2027-12-31 10:22:01',
'2028-12-31 10:22:01', '2029-12-31 10:22:01'],
dtype='datetime64[ns]', freq='A-DEC')
freq 参数说明
参数 必选 类型 说明 S ture string 秒级 Min ture string 分 H ture string 时 D ture string 天 W ture string 周 M ture string 月 Y ture string 年
注意:级别前面的数字表示多长时间间隔的(5H,就是5小时间隔)