python - Taking the difference between two dates using pandas? -


i trying take time difference between 2 dates using pandas , having trouble.

the format dates in follows:

2016/07/06 03:10:39 

using pandas.to_datetime can these datetime64 type cannot figure out way take difference of these types.

here basis of code:

df2.end = to_datetime(df1.end) df2.start = to_datetime(df1.start) 

if print these objects dataframe here get:

series([], name: end, dtype: datetime64[ns]) series([], name: start, dtype: datetime64[ns]) 

end:

0    2016-07-06 04:39:16 1    2016-07-06 04:13:30 2    2016-07-06 03:51:30 

start

0    2016-07-06 05:01:14 1    2016-07-06 04:39:06 2    2016-07-06 04:13:27 

i have tried following:

df2.difference = df2.end-df2.start 

and following error:

typeerror: ufunc subtract cannot use operands types dtype('<m8[ns]') , dtype('o') 

that's work perfectly:

>>> import pandas >>> x = pandas.to_datetime("2016/07/06 03:10:39") >>> y = pandas.to_datetime("2016/07/06 03:11:21") >>> y-x timedelta('0 days 00:00:42') 

post code if still can't figure problem.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -