Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.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,学习时间差,无法解决时间减法问题。。 我想找出两列之间的时间差。 很简单 df['TimeDiff']=(df['LogOut']-df['LogIn']) 原因“类型错误:不支持的操作数类型-:'str'和'str'” 我猜,这个错误是由于一些时间戳是空的。。。 但不能确定,因为我是python新手 表格图像在这里 请告知。尝试使用 df['LogOut'] = pd.to_datetime(df['LogOut']) df['LogIn'] = pd.to_datetime(df['LogI

学习时间差,无法解决时间减法问题。。 我想找出两列之间的时间差。 很简单

df['TimeDiff']=(df['LogOut']-df['LogIn'])

原因“类型错误:不支持的操作数类型-:'str'和'str'”

我猜,这个错误是由于一些时间戳是空的。。。 但不能确定,因为我是python新手

表格图像在这里

请告知。

尝试使用

df['LogOut'] = pd.to_datetime(df['LogOut'])
df['LogIn'] = pd.to_datetime(df['LogIn'])
这将把列转换为datetime,这是受支持的


您还可以查看软件包
timedelta

excel工作表登录/退出列受保护

所以我将文件保存在.csv中,发现空单元格实际上不是空的,每个单元格包含8个空格

尝试: df['LogOut'].替换(“,”)

df['LogOut'].fillna(“0”)

最后

df['LogOut']=pd.to_datetime(df['LogOut'])

导致了相同的错误。。。(ParserError:字符串不包含日期:)…

花了一段时间

空电池导致了问题

解决办法是


df['LogOut']=pd.to_datetime(df['LogOut'],errors='commisse')

发生这种情况是因为
df['LogOut']
df['LogIn']
属于
str
类型,所以首先在
timestamp
datetime
中更改它们,然后尝试
df['TimeDiff'=(df['LogOut']-df['LogIn'])
再次。您的选项导致:ParserError:String不包含日期:P.S.奇怪,因为这两列只有时间戳。。。或者是空的,;(我假设行值为空,您可以执行
df['col name'].fillna(“value”)
,然后尝试转换为
datetime