python - Python:以所需格式创建时间序列数据
问题描述
任何人都可以帮助以以下格式在 Python 中生成时间序列数据。日期-月-年小时-分钟-秒。从 2020 年 4 月 1 日至 2021 年 3 月 31 日:01/04/2020 0.00.00 至 31/03/2021 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]
查看https://strftime.org/fmt
中的语法,了解所需的时间格式
推荐阅读
- python - 为什么 Python 装饰器会这样做?不同的输出?
- c# - MonoGame 我需要使用 Draw() - 还是只使用 Update()
- opencv - 无法使用 Yolo.v3 从 lg-simulator 检测图像中的对象
- javascript - 使用 window.location 设置样式
- python-3.x - 在python中插入NULL会出错
- javascript - 反应.js | 通过道具样式与编写 CSS-in-JS
- javascript - ./src/App.js 第 6:19 行:“组件”未定义 no-undef
- python - Python将字符串列表转换为整数列表
- javascript - 使用 JS/jQuery 将 tabindex 附加到输入标签
- javascript - Fullcalendar - 来自外部文件的 JSON 数据问题