Q:

Fill in missing values using climatology data except for current year

df.groupby([df.index.month, df.index.day])[vars_rs].transform(lambda y: y.fillna(y.median()))

I am filling missing values in a dataframe with median values from climatology. The days range from Jan 1 2010 to Dec 31st 2016. However, I only want to fill in missing values for days before current date (say Oct 1st 2016). How do I modify the statement?

A:

The algorithm would be:

Get a part of the data frame which contains only rows filtered by date with a boolean mask
Perform required replacements on it
Append the rest of the initial data frame to the end of the resulting data frame.

Dummy data:
df = pd.DataFrame(np.zeros((5, 2)),columns=['A', 'B'],index=pd.date_range('2000',periods=5,freq='M'))

            A   B
2000-01-31  0.0 0.0
2000-02-29  0.0 0.0
2000-03-31  0.0 0.0
2000-04-30  0.0 0.0
2000-05-31  0.0 0.0

The code
vars_rs = ['A', 'B']
mask = df.index < '2000-03-31'
early = df[mask]
early = early.groupby([early.index.month, early.index.day])[vars_rs].transform(lambda y: y.replace(0.0, 1))  # replace with your code
result = early.append(df[~mask])

So the result is
            A   B
2000-01-31  1.0 1.0
2000-02-29  1.0 1.0
2000-03-31  0.0 0.0
2000-04-30  0.0 0.0
2000-05-31  0.0 0.0

