I have a dataframe with the following structure:
date position quantity Unit
0 2015-01-01 00:00:00 1 720 MAW
Based on the conditions I set I wish to reorder dates during the daylight savings time in October (1 hour gets added here) based on the "position" column. So I subseted the dataframe and got the index values back:
indexData = data[(data.date.dt.hour >= 2) & (data.date.dt.hour < 3) & (data.date.dt.day == 25) & (data.date.dt.month == 10) & (data.date.dt.year == 2015)].index
So when I do this I can see that the range is ordered correctly (but not yet replaced in the dataframe):
data.iloc[indexData[0]:(indexData[-1])+1].sort_values("position")
date position quantity Unit
28521 2015-10-25 02:00:00 25305 420 MAW
28523 2015-10-25 02:15:00 25306 418 MAW
28524 2015-10-25 02:30:00 25307 415 MAW
28526 2015-10-25 02:45:00 25308 415 MAW
28520 2015-10-25 02:00:00 25309 410 MAW
28522 2015-10-25 02:15:00 25310 407 MAW
28525 2015-10-25 02:30:00 25311 399 MAW
28527 2015-10-25 02:45:00 25312 378 MAW
BUT when I try to assign this range to the original data drame it does not change:
data.iloc[indexData[0]:(indexData[-1])+1] = data.iloc[indexData[0]:(indexData[-1])+1].sort_values("position")
# here I check the range if updated
data[(data.date.dt.hour >= 2) & (data.date.dt.hour < 3) & (data.date.dt.day == 25) & (data.date.dt.month == 10) & (data.date.dt.year == 2015)]
date position quantity Unit
28520 2015-10-25 02:00:00 25309 410 MAW
28521 2015-10-25 02:00:00 25305 420 MAW
28522 2015-10-25 02:15:00 25310 407 MAW
28523 2015-10-25 02:15:00 25306 418 MAW
28524 2015-10-25 02:30:00 25307 415 MAW
28525 2015-10-25 02:30:00 25311 399 MAW
28526 2015-10-25 02:45:00 25308 415 MAW
28527 2015-10-25 02:45:00 25312 378 MAW
Any ideas where I am going wrong or should try?