It'd be nice if there was a way to easily broadcast arithmetic operations on Series/DataFrames with DatetimeIndexes. For example, say you have monthly data, calculate the monthly mean, and want to multiply the original series by the monthly factor.

import numpy as np
import pandas as pd
idx = index=pd.date_range('1970-01-01', end='2015-01-01', freq='MS')
s = pd.Series(np.random.randn(len(idx)), name='ts',
              index=idx)
mf = s.groupby(lambda x: x.month).mean()

In [3]: s
Out[3]:
1970-01-01   -1.032080
1970-02-01   -0.706686
1970-03-01   -0.380895
1970-04-01    0.322074
1970-05-01   -1.545298
                ...
2014-09-01   -0.787646
2014-10-01   -2.444045
2014-11-01   -0.646474
2014-12-01   -0.291925
2015-01-01    0.399430
Freq: MS, Name: ts, dtype: float64

In [4]: mf
Out[4]:
1     0.184326
2    -0.069534
3    -0.146372
4     0.018643
5     0.050393
        ...
8    -0.088188
9     0.148328
10    0.105042
11    0.219308
12    0.000997
Name: ts, dtype: float64

Right now you need something like (this could be simplified)

tmp = s.copy()
tmp.index = s.index.month
tmp = tmp * mf
tmp.index = s.index
s

It'd be nice to use the fact that s is a datetimeindex to allow some broadcasting over the years. Something like

s.mul(mf, freq='M')

A similar case is when both s and mf have DatetimeIndexes. Then s.mul(mf, freq='M') upsamples the lower frequency mf to a monthly frequency, fills, and multiplies.

Another example from SO

Comment From: jreback

dont you just want this? s.groupby(lambda x: x.month).transform('mean')*s

Comment From: TomAugspurger

In this case that's equivalent, and probably simpler. But sometimes the monthly factors, the output of s.groupby(lambda x: x.month).mean() are interesting on their own, or more involved to calculate (e.g. the coefficients from a regression on pd.get_dummies(df.index.month)). In these cases you could calculate the coefficients, and then go through another round of groupby.transform, but that's not what I'd initially think to try.

Comment From: jreback

ok, how about we make this a doc issue then with some examples of doing this in cookbook or transform section?

in theory .align could do this, but would be nice to see syntax for that.

Comment From: jbrockmendel

-1 on adding new API for this