Q:

Flag dates that are between a range

I have the following dataframe:
     exdiv_date    expiry_date
0    2015-09-18    2015-12-18
1    2015-11-20    2015-12-18
2    NaN           2016-01-20
3    2015-12-26    2016-01-15
4    NaN           2015-11-21

I need to flag each row where the exdiv_date is after today and before the expiry_date.  The output should be:
     exdiv_date    expiry_date   flag
0    2015-09-18    2015-12-18    False
1    2015-11-20    2015-12-18    True
2    NaN           2016-01-20    False
3    2015-12-26    2016-01-15    True
4    NaN           2015-11-21    False

As per the example, some rows do not have an exdiv_date (ie: NaN).  I have ensured the exdiv_date and expiry_date are of the same type as follows:
df['exdiv_date'] = pd.to_datetime(df['exdiv_date'])
df['expiry_date'] = pd.to_datetime(df['expiry_date'])

I have tried doing this as follows:
mask = (df['exdiv_date'] > dt.date.today) & (df['exdiv_date'] < df['expiry_date'])
df.loc[mask, 'flag'] = True

But I get an error: TypeError: Cannot convert input to Timestamp
I presume the error is because of the NaN's but im not sure how to get around it. 

A:

There is problem with brackets - use dt.date.today(). 
You can use alternatively np.where:
import datetime as dt

#  exdiv_date expiry_date
#0 2015-09-18  2015-12-18
#1 2015-11-20  2015-12-18
#2        NaT  2016-01-20
#3 2015-12-26  2016-01-15
#4        NaT  2015-11-21

mask = (df['exdiv_date'] > dt.date.today()) & (df['exdiv_date'] < df['expiry_date'])
df.loc[mask, 'flag'] = True
print df
#  exdiv_date expiry_date  flag
#0 2015-09-18  2015-12-18   NaN
#1 2015-11-20  2015-12-18  True
#2        NaT  2016-01-20   NaN
#3 2015-12-26  2016-01-15  True
#4        NaT  2015-11-21   NaN
#if condition true add value True else add False to column flag
df['flag'] = np.where((df['exdiv_date'] > dt.date.today()) & (df['exdiv_date'] < df['expiry_date']), 'True', 'False')
print df
#  exdiv_date expiry_date   flag
#0 2015-09-18  2015-12-18  False
#1 2015-11-20  2015-12-18   True
#2        NaT  2016-01-20  False
#3 2015-12-26  2016-01-15   True
#4        NaT  2015-11-21  False

