My sample df is like this:
hr temp1
hour
1900-01-01 00:00:00 0 19
1900-01-01 00:15:00 0 19
1900-01-01 00:30:00 0 19
1900-01-01 00:45:00 0 19
1900-01-01 01:00:00 1 18
1900-01-01 01:15:00 1 18
1900-01-01 01:30:00 1 18
1900-01-01 01:45:00 1 18
1900-01-01 02:00:00 2 18
1900-01-01 02:15:00 2 18
1900-01-01 02:30:00 2 18
1900-01-01 02:45:00 2 18
1900-01-01 03:00:00 3 17
expected output(after transformation):
hr temp1 temp
hour
1900-01-01 00:00:00 0 19 19 # as it is (current elem)
1900-01-01 00:15:00 0 19 18 # next group(hr=1) element
1900-01-01 00:30:00 0 19 18 # next group(hr=1) element
1900-01-01 00:45:00 0 19 18 # next group(hr=1) element
1900-01-01 01:00:00 1 18 18 # as it is (current elem)
1900-01-01 01:15:00 1 18 18 # next group(hr=2) element
1900-01-01 01:30:00 1 18 18 # next group(hr=2) element
1900-01-01 01:45:00 1 18 18 # next group(hr=2) element
1900-01-01 02:00:00 2 18 18 # as it is (current elem)
1900-01-01 02:15:00 2 18 17 # next group(hr=3) element
1900-01-01 02:30:00 2 18 17 # next group(hr=3) element
1900-01-01 02:45:00 2 18 17 # next group(hr=3) element
1900-01-01 03:00:00 3 17 17 # as it is (current elem)
So basically I want to put the next group value to the current group. keeping the first value of the row be same.
Since I have done resampling by 15min so there are repeated values for each hr group.
I ain't able to solve it.
Edit:
One solution is to do the shifting and assign value before resampling. because when I will pad I will have the next group element values. I can change the every group 1st value to be as row['temp'] something like this.
this is the data before resampling:
temp1 hr
hour
1900-01-01 00:00:00 19 0
1900-01-01 01:00:00 18 1
1900-01-01 02:00:00 18 2
1900-01-01 03:00:00 17 3
Edit2:
Before resampling:
df[['temp1']].shift(-1).fillna(df.iloc[df.shape[0]-1]['temp1']).resample('900s').pad()
and then do the 1st group 1st element assignment.
but this looks too complex.