分享处理月初和月末的日期代码
import pandas as pd
beginDate = ‘2019-10-01’
endDate = ‘2019-12-31’
date_index = pd.date_range(beginDate, endDate)
days = [pd.Timestamp(x).strftime(“%Y-%m-%d”) for x in date_index.values]
tmp = []
for index, v in enumerate(days):
if index == len(days)-1:
tmp.append(days[index])
if index == 0:
tmp.append(days[0])
else:
_ = v.split(‘-’)[2]
if _ == ‘01’:
tmp.append(days[index-1])
tmp.append(days[index])
print(tmp)
老铁可以用下 markdown 编辑器里的代码块把代码框起来 😃