I have a DataFrame with about 20 million rows and a DatetimeIndex. There are data from different years, and I would like to assign them all to the same year by changing the timestamps. The statements below accomplish this, but are a bit slower than I would like (double-digit seconds).
new_index = [ts.replace(year=2014) for ts in df.index]
df.index = new_index
The data are not evenly spaced, so I cannot generate a new index easily. Is there a better way?