我想将“ Duration” = n的行重复n次,且n大于零,同时将日期递增到n。这是我拥有的
Event StartDate Endate Durate
xx o1/o1/2018 o3/o1/2018 2
xxx o1/o1/2018 o2/o1/2018 1
这是我想要的:
Event StartDate Endate Durate
xx 01/01/2018 01/01/2018 0
xx 01/01/2018 03/o1/2018 2
xx 02/01/2018 03/o1/2018 2
xxx 01/01/2018 02/01/2018 1
xxx 02/01/2018 02/o1/2018 1
这是我尝试过的:
for i in (data['Durate']):
for i in range(i):
data.index:i+1= (data['StartDate']+1) + pd.DateOffset(1)
让我们说一下持续时间是否为2;我以startDate递增2到行数
答案 0 :(得分:0)
这是您可以做的:您可以使用iterrows来做到这一点;像这样:
data_data.copy(deep=True)
for _, val in data.iterrows():
if val['Durate'] > 0:
count = val['Durate']
for i in range(count):
val['Durate'] = val['Startdate'] + pd.DateOffset(days=1)
data_ = data_.append(val)
data_.sort_values('Event', inplace=True)