Consider a series holding timedelta64[ns]
that measures at the time difference between two events A and B:
> time_deltas499900 -1 days +23:45:13
499916 -1 days +23:50:57
499917 00:03:27
499919 00:17:45
499920 00:16:56
499921 -1 days +23:59:26
499922 00:16:34
499923 00:15:46
499928 00:12:56
499929 00:05:54...
499970 00:00:48
499971 -1 days +23:58:32dtype: timedelta64[ns]
How can I identify negative deltas? (e.g. A happening before B).
This does not work:
> time_deltas[time_deltas<0]
TypeError: invalid type comparison
Also consider the following:
# Negative time delta example:
> time_deltas.iloc[-1]
Timedelta('-1 days +23:58:32')# Values seem to have integer representation in ns
> time_deltas.iloc[-1].value
-88000000000# Positive time delta example:
> time_deltas.iloc[-2]
Timedelta('0 days 00:00:48')# Again, values seem to have integer representation in ns
> time_deltas.iloc[-1].value
48000000000
But then:
# Trying to use the internal representation fails
> time_deltas.apply(lambda x: x.value>0)
AttributeError: 'numpy.timedelta64' object has no attribute 'value'# Same with
> time_deltas.apply(lambda x: x['value']>0)
IndexError: invalid index to scalar variable.