I want to fill a column with particular dates. First, I create a column of dates filled only with the date of today. Then, I compute the date I want to replace for each location. The index is in the following format: '%Y-%m-%d'
The computation works well. It is the last line which does not work
There is my code:
for j in range(1, 154):
result['LTD_' + str(j)] = dt.date(dt.datetime.now().year,dt.datetime.now().month,dt.datetime.now().day) #creating a column of dates filled with today day
for i in range(0, len(result.index)):
date_selected = result.iloc[[i]].index
date_month = add_months(date_selected,j)
delivery_month = date_month.month
delivery_year = date_month.year
delivery = dt.date(delivery_year, delivery_month, result[(result.index.month == (delivery_month)) & (result.index.year == delivery_year)].index.day.min())
delloc = result.index.get_loc(str(delivery))
ltdloc = delloc - 3
result.iloc[[i]]['LTD_' + str(j)] = dt.date(result.iloc[[ltdloc]].index.year, result.iloc[[ltdloc]].index.month, result.iloc[[ltdloc]].index.day)
The last line does not work to replace the today date by the computed date. Nothing happened. date.replace generates an error.
result.iloc[[i]]['LTD_' + str(j)] = 0it failed? If useprint(dt.date(result.iloc[[ltdloc]].index.year, result.iloc[[ltdloc]].index.month, result.iloc[[ltdloc]].index.day))it failed?result.iloc[[i]]['LTD_' + str(j)] = 0, nothing happened. I have still the today date (2017-05-25). However,print(dt.date(result.iloc[[ltdloc]].index.year, result.iloc[[ltdloc]].index.month, result.iloc[[ltdloc]].index.day))gives the good date in the format'%Y-%m-%d'I want to replace inresult.iloc[[i]]['LTD_' + str(j)].result['LTD_' + str(j)].iloc[i]orresult['LTD_' + str(j)].iloc[[i]]should works.result.loc[result.index[i], 'LTD_' + str(j)]