Ok, my real problem is bigger than this, but I have a simple working example.
>>> import pandas as pd
>>> import numpy as np
>>> a = pd.DataFrame(np.array([[2, 1990], [4,1991], [5,1992]]), \
... index=[1,2,3], columns=['var', 'yr'])
>>> a
var yr
1 2 1990
2 4 1991
3 5 1992
>>> b = pd.DataFrame(index=a.index, columns=['new_var'])
>>> b
new_var
1 NaN
2 NaN
3 NaN
>>> b[a.yr<1992].loc[:, 'new_var'] = a[a.yr<1992].loc[:, 'var']
>>> b
new_var
1 NaN
2 NaN
3 NaN
I desire the following output:
>>> b
new_var
1 2
2 4
3 NaN