【发布时间】:2021-11-09 00:35:38
【问题描述】:
我将如何编写代码来启用dates 中的起始年份和结束年份。我想使用 pandas 或 numpy 来显示开始和结束年份。
import numpy as np
import pandas as pd
dates = ['2017-09-01 00:00:00', '2017-10-01 00:00:00', '2017-11-01 00:00:00', '2017-11-01 00:00:00', '2017-11-01 00:00:00', '2017-12-01 00:00:00', '2018-01-01 00:00:00', '2018-02-01 00:00:00', '2018-03-01 00:00:00', '2018-04-01 00:00:00', '2018-05-01 00:00:00', '2018-06-01 00:00:00', '2018-07-01 00:00:00', '2018-08-01 00:00:00', '2018-09-01 00:00:00', '2018-10-01 00:00:00', '2018-11-01 00:00:00', '2018-12-01 00:00:00', '2018-12-01 00:00:00', '2019-01-01 00:00:00']
预期输出:
Starting year: 2017
Ending year: 2019
【问题讨论】:
标签: python arrays pandas numpy datetime