I would like to vectorize the computation of the overlap of time intervals using np.minimum
on pd.Series
:
np.minimum(
pd.to_datetime('2018-01-16 21:43:00'),
pd.Series([pd.to_datetime('2018-01-16 21:44:00'), pd.to_datetime('2018-01-16 21:41:00')]))
However, this results in the following TypeError
:
TypeError Traceback (most recent call last)
<ipython-input-84-07083aa6dce1> in <module>()
1 np.minimum(
2 pd.to_datetime('2018-01-16 21:43:00'),
----> 3 pd.Series([pd.to_datetime('2018-01-16 21:44:00'), pd.to_datetime('2018-01-16 21:41:00')]))
pandas\_libs\tslibs\timestamps.pyx in pandas._libs.tslibs.timestamps._Timestamp.__richcmp__()
TypeError: Cannot compare type 'Timestamp' with type 'int'
Using a np.array
works like a charm (using .values
not):
np.minimum(
pd.Series([1, pd.to_datetime('2018-01-16 21:43:00')])[1],
np.array([pd.to_datetime('2018-01-16 21:44:00'), pd.to_datetime('2018-01-16 21:41:00')]))
Any ideas?