I have a df with a DateTimeIndex of 30 minute intervals over a long period (> 1 year), so >17520 rows. For reasons related to daylight savings, two of the index values are repeated in the index and two values are missing. So the duplicated values are:
In[1]: df[df.index.duplicated('first')]
Out[2]:
a b c
timestamp
2012-10-07 01:00:00 NaN NaN NaN
2012-10-07 01:30:00 NaN NaN NaN
2013-10-06 01:00:00 NaN NaN NaN
2013-10-06 01:30:00 NaN NaN NaN
I want to change these to the missing values, 1 hour later:
In[3]: df[df.index.duplicated('first')].shift(1,freq="H")
Out[4]:
a b c
timestamp
2012-10-07 02:00:00 NaN NaN NaN
2012-10-07 02:30:00 NaN NaN NaN
2013-10-06 02:00:00 NaN NaN NaN
2013-10-06 02:30:00 NaN NaN NaN
But this doesn't change the index:
df[df.index.duplicated('first')] = df[df.index.duplicated('first')].shift(1,freq="H")
What would?