Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以小时为单位获取Datetime之间的差异,将两个四舍五入设置为2_Python_Pandas_Numpy_Dataframe_Datetime - Fatal编程技术网

Python 以小时为单位获取Datetime之间的差异,将两个四舍五入设置为2

Python 以小时为单位获取Datetime之间的差异,将两个四舍五入设置为2,python,pandas,numpy,dataframe,datetime,Python,Pandas,Numpy,Dataframe,Datetime,通过四舍五入到小数点后2位,获得两个datetime之间以小时为单位的差值 > `Started Ended` Hours 2020-10-01 09:29:20 2020-10-01 17:43:28 8.2 2020-10-31 09:26:43 2020-10-31 18:57:40 9.5 2020-10-31 09:18

通过四舍五入到小数点后2位,获得两个datetime之间以小时为单位的差值

> `Started                     Ended`                     Hours
   2020-10-01 09:29:20         2020-10-01 17:43:28         8.2
   2020-10-31 09:26:43         2020-10-31 18:57:40         9.5
   2020-10-31 09:18:57         2020-10-31 21:06:30         11.8
与and一起使用,最后除以and使用:

另一个例子:

from datetime import datetime
beg = '08:00:10'
end = '17:16:24' 

print('end = ',end, 'type: ',type(end))

dur = datetime.strptime(end, '%H:%M:%S') - datetime.strptime(beg, '%H:%M:%S')

result = dur.total_seconds()/3600

result = round(result, 2)

print(result)
from datetime import datetime
beg = '08:00:10'
end = '17:16:24' 

print('end = ',end, 'type: ',type(end))

dur = datetime.strptime(end, '%H:%M:%S') - datetime.strptime(beg, '%H:%M:%S')

result = dur.total_seconds()/3600

result = round(result, 2)

print(result)