Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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 从具有相同值的另一列中减去一列_Python_Pandas - Fatal编程技术网

Python 从具有相同值的另一列中减去一列

Python 从具有相同值的另一列中减去一列,python,pandas,Python,Pandas,我试图从两个datetime列中减去,得到秒差,但我的问题是,有些列彼此相同,所以当减去它们时,我达到了86399秒的边界。我要显示的是0。有些项目的减法正确,因为它们是不同的值。下面是我的代码行,其中有两个日期时间示例: 2018-08-01 00:04:30 2018-08-01 00:04:30 2018-08-01 00:26:32 2018-08-01 00:27:30 df['sessiontime'] = (df['logofftime'] - df['logontime'])

我试图从两个datetime列中减去,得到秒差,但我的问题是,有些列彼此相同,所以当减去它们时,我达到了86399秒的边界。我要显示的是0。有些项目的减法正确,因为它们是不同的值。下面是我的代码行,其中有两个日期时间示例:

2018-08-01 00:04:30 2018-08-01 00:04:30
2018-08-01 00:26:32 2018-08-01 00:27:30


df['sessiontime'] = (df['logofftime'] - df['logontime']).dt.seconds
我假设答案很简单,但我尝试使用一个.where方法,但pandas文档说该方法已被弃用。任何帮助都将不胜感激


我正在使用pandas 0.23.3和python 3.6.6

因此,我错误地从原始SQL查询中提取了注销时间,而注销时间实际上早于注销时间,因此它认为这本质上是全年的差异。我依赖于excel文件的输出,该文件不能正确显示ms

你想给我们看警告信息吗?我没有收到警告信息。输出不是我所期望的。我原以为是0,但现在是86399,在我这边效果很好。我一定没有看到我这边有什么东西。