[英]TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'datetime.time'
I have a pandas DataFrame:我有一个 pandas DataFrame:
In [33]: df
Out[33]:
userId 2021-01-29 2021-01-30 2021-01-01
0 Nl3AG93Ss7L5aj 09:00:00 NaN NaN
1 NaN NaN NaN NaN
2 AbVpBHdfrI5aj1 12:10:00 NaN NaN
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
5 sad9283ds7L5aj1 NaN 15:35:00 22:22:00
6 NaN NaN NaN NaN
7 NaN NaN NaN NaN
8 NaN NaN NaN NaN
I need to get the date and time the script started working, but I get the error:我需要获取脚本开始工作的日期和时间,但出现错误:
TypeError Traceback (most recent call last)
<ipython-input-40-7ed51ff0c115> in <module>
1 for column in df.columns.tolist():
----> 2 for i in df.loc[df[column].apply(lambda x: isinstance(x, datetime.time))][column]: print(column + i)
3
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'datetime.time'
Also I can output the schedule without merging:我也可以 output 计划而不合并:
In [22]: for column in df.columns.tolist():
...: for time in df.loc[df[column].apply(lambda x: isinstance(x, datetime.time))][column]: print(column, time)
...:
2021-01-29 00:00:00 09:00:00
2021-01-29 00:00:00 12:10:00
2021-01-30 00:00:00 15:35:00
2021-01-01 00:00:00 22:22:00
Try converting the things into strings and just using the +
as string concat...尝试将内容转换为字符串,然后将+
用作字符串连接...
for column in df.columns.tolist():
for i in df.loc[df[column].apply(lambda x: isinstance(x, datetime.time))][column]: print(column.strftime("%Y-%m-%d”) +" "+ i.strftime("%H:%M:%S”))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.