python - Dividing a series containing datetime by a series containing an integer in Pandas -


i have series s1 of type datetime , has time represents range between start time , end time - typical values 7 days, 4 hours 5 mins etc. have series s2 contains integers number of events happened in time range.

i want calculate event frequency by:

event_freq = s1 / s2

i error:

cannot operate on series out rhs of series/ndarray of type datetime64[ns] or timedelta

whats best way fix this?

thanks in advance!

example of s1 is:

some_id  1          2012-09-02 09:18:40 3          2012-04-02 09:36:39 4          2012-02-02 09:58:02 5          2013-02-09 14:31:52 6          2012-01-09 12:59:20 

example of s2 is:

some_id 1           3 3           1 4           1 5           2 6           1 8           1 10          3 12          2 

this might possibly bug works operate on underlying numpy array so:

import pandas pd pandas import series  startdate = series(pd.date_range('2013-01-01', '2013-01-03')) enddate = series(pd.date_range('2013-03-01', '2013-03-03'))  s1 = enddate - startdate s2 = series([2, 3, 4])  event_freq = series(s1.values / s2) 

here series:

>>> s1 0   59 days, 00:00:00 1   59 days, 00:00:00 2   59 days, 00:00:00 dtype: timedelta64[ns]  >>> s2 0    2 1    3 2    4 dtype: int64  >>> event_freq 0   29 days, 12:00:00 1   19 days, 16:00:00 2   14 days, 18:00:00 dtype: timedelta64[ns] 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -