简体   繁体   English

OutOfBoundsDatetime:越界纳秒时间戳:1-01-01 00:00:34

[英]OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-01 00:00:34

I have a column in a csv file that says start time .我在 csv 文件中有一个列,上面写着start time And the values are like this:值是这样的:

0:10:52
4:33:34
1:41:06
21:19:40
0:30:55
22:27:23

I wrote the following piece of code to change the datatype of this column to "time":我编写了以下代码将该列的数据类型更改为“时间”:

log_file['start time'] = pd.to_datetime(log_file['start time']).dt.time

When I run this piece of code, it gives me the following error:当我运行这段代码时,它给了我以下错误:

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-01 00:00:34 OutOfBoundsDatetime:越界纳秒时间戳:1-01-01 00:00:34

Can someone please help me understand this error and how to troubleshoot it.有人可以帮我理解这个错误以及如何解决它。 I went through the other outofboundsdatetime posts but I couldn't really understand the logic.我浏览了其他 outofboundsdatetime 帖子,但我无法真正理解逻辑。

Thanks!谢谢!

Problem is that some time values are not zero padding, you can pad column value with Series.str.zfill问题是某些时间值不是零填充,您可以使用Series.str.zfill填充列值

log_file['end time'] = (pd.to_datetime(
    (log_file['start time']
     .str.split(':', expand=True)
     .apply(lambda col: col.str.zfill(2))
     .fillna('00')
     .agg(':'.join, axis=1))
).dt.time)
print(log_file)

  start time  end time
0    0:10:52  00:10:52
1    4:33:34  04:33:34
2    1:41:06  01:41:06
3   21:19:40  21:19:40
4    0:30:55  00:30:55
5   22:27:23  22:27:23
6     0:0:34  00:00:34
7      0::34  00:00:34
8        ::4  00:00:04
9         :4  00:04:00

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 超出范围的纳秒级时间戳记:1-01-01 00:00:00 - Out of bounds nanosecond timestamp: 1-01-01 00:00:00 返回特定月份和年份的 df 行 python pandas OutOfBoundsDatetime:越界纳秒时间戳:1-01-01 00:00:00 - Return rows of df of particular month and year python pandas OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-01 00:00:00 越界纳秒时间戳:日期的 1-01-01 00:00:00 - Out of bounds nanosecond timestamp: 1-01-01 00:00:00 for dates OutOfBoundsDatetime:越界纳秒时间戳 - OutOfBoundsDatetime: Out of bounds nanosecond timestamp Postgres时间戳不接受2017-01-01T23:00:00-00:00 - Postgres timestamp not accepting 2017-01-01T23:00:00-00:00 如何将时间戳(datetime.datetime(2012,1,1,1,0)转换为2012-01-01 01:00:00 - How to convert timestamp (datetime.datetime(2012, 1, 1, 1, 0) into 2012-01-01 01:00:00 pandas:无法使用Timestamp的这些索引器[2016-08-01 00:00:00]对DatetimeIndex进行位置索引 - pandas: cannot do positional indexing on DatetimeIndex with these indexers [2016-08-01 00:00:00] of Timestamp 超出范围的纳秒级时间戳 - Out of bounds nanosecond timestamp 从 CSV 导入时转换日期,OutOfBoundsDatetime:超出范围纳秒时间戳。 Pandas - Converting dates when importing from CSV, OutOfBoundsDatetime: Out of bounds nanosecond timestamp. Pandas 将 2020-09-01T00:00:00-05:00 时间戳转换为 dd-mm-yyyy - Convert 2020-09-01T00:00:00-05:00 timestamp to dd-mm-yyyy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM