pandas-dev/pandas (original) (raw)
I'm using pandas 0.12 and numpy 1.7.1.
I'm trying to calculate the number of business days between two columns of dates. Not all rows have valid dates though, and pd.date_range does not have an ignore errors option, so I'm getting this error:
In [439]: td = pd.DataFrame({'a':[pd.Timestamp('2010-1-1'), pd.Timestamp('2010-2-1')], 'b':[pd.Timestamp('2010-1-10'), p d.Timestamp('2010-2-9')]})
In [440]: td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1) Out[440]: 0 6 1 7 dtype: int64
In [441]: td = pd.DataFrame({'a':[pd.Timestamp('2010-1-1'), pd.Timestamp('2010-2-1')], 'b':[pd.Timestamp('2010-1-10'), p d.NaT]})
In [442]: td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1)
AttributeError Traceback (most recent call last) in () ----> 1 td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1)
C:\Python27\lib\site-packages\pandas\core\frame.pyc in apply(self, func, axis, broadcast, raw, args, **kwds) 4414 return self._apply_raw(f, axis) 4415 else: -> 4416 return self._apply_standard(f, axis) 4417 else: 4418 return self._apply_broadcast(f, axis)
C:\Python27\lib\site-packages\pandas\core\frame.pyc in _apply_standard(self, func, axis, ignore_failures) 4489 # no k defined yet 4490 pass -> 4491 raise e 4492 4493
AttributeError: ("'NaTType' object has no attribute 'tz'", u'occurred at index 1')
In [443]: