I have a pandas DataFrame looking like this :
x1 x2 x3 x4
Date Time
2017-01-03 09:00:00 0.000097 0.000259 0.000629 0.000142
09:20:00 0.000046 0.000044 0.000247 0.000134
09:40:00 0.000021 0.000032 0.000171 0.000105
10:00:00 0.000033 0.000040 0.000136 0.000178
10:20:00 0.000079 0.000157 0.000094 0.000083
.....
17:00:00 0.000032 0.000137 0.000024 0.000028
However, i want to reindex the second index, by one 20min bin and I would like it to look like this:
x1 x2 x3 x4
Date Time
2017-01-03 09:20:00 0.000097 0.000259 0.000629 0.000142
09:40:00 0.000046 0.000044 0.000247 0.000134
10:00:00 0.000021 0.000032 0.000171 0.000105
10:20:00 0.000033 0.000040 0.000136 0.000178
10:40:00 0.000079 0.000157 0.000094 0.000083
.....
17:20:00 0.000032 0.000137 0.000024 0.000028
So all the values stay the same, only the second index is renamed, everything else stays the same.
I've tried following code:
x.reindex(pd.date_range(pd.Timestamp('09:20:00'), pd.Timestamp('17:20:00'), freq="20min").time, level=1)
But it just moves the index and the values stay at the same place.
x1 x2 x3 x4
Date Time
2017-01-03 09:20:00 0.000046 0.000044 0.000247 0.000134
09:40:00 0.000021 0.000032 0.000171 0.000105
10:00:00 0.000033 0.000040 0.000136 0.000178
10:20:00 0.000079 0.000157 0.000094 0.000083
.....
17:00:00 0.000032 0.000137 0.000024 0.000028
It does not even ad the bin for 17:20:00.
However, if I also tried to shift the values after grouping them like this:
x.groupby(level=1).shift(1)
or:
x.groupby(level=1).shift(1, freq='20min')
but that did not work at all.