1 回答
TA贡献1785条经验 获得超8个赞
我不确定我是否理解逻辑,但这提供了您正在寻找的输出:
last_row = df.sort_values('End_Date')[-1:]
new_rows = []
start_date = last_row['Start_Date'].iloc[0]
end_date = last_row['End_Date'].iloc[0]
for i in range(1,5):
start_date = end_date + dt.timedelta(days=1)
end_date = end_date + dt.timedelta(days=7)
end_dt_id = dt.datetime.strftime(end_date, '%d%b%y').upper()
new_rows.append([end_dt_id,start_date, end_date])
df = pd.concat([
df,
pd.DataFrame(new_rows, columns=['End_Dt_Id', 'Start_Date', 'End_Date'])
])
for col in ['Start_Date', 'End_Date']:
df[col] = pd.to_datetime(df[col]).dt.strftime('%d-%m-%Y')
退货:
End_Dt_Id Start_Date End_Date
18AUG19 12-08-2019 18-08-2019
25AUG19 19-08-2019 25-08-2019
01SEP19 26-08-2019 01-09-2019
08SEP19 02-09-2019 08-09-2019
15SEP19 09-09-2019 15-09-2019
22SEP19 16-09-2019 22-09-2019
12SEP19 23-09-2019 12-09-2019
19SEP19 13-09-2019 19-09-2019
26SEP19 20-09-2019 26-09-2019
03OCT19 27-09-2019 03-10-2019
10OCT19 04-10-2019 10-10-2019
添加回答
举报