Python 2.7:Pandas日期时间不适用于将来的日期吗?

编程入门 行业动态 更新时间:2024-10-08 13:32:57
本文介绍了Python 2.7:Pandas日期时间不适用于将来的日期吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我遇到ValueError时,我试图将DataFrame列(字符串)转换为datetime格式.这是使用字符串而不是DataFrame列的可复制代码(和错误):

I was trying to convert a DataFrame column (string) into datetime format when I encountered a ValueError. Here is a reproducible code (and the error) using a string instead of an DataFrame column:

>>> import pandas as pd >>> pd.to_datetime('2007-08-17', format='%Y-%m-%d') #Works fine Timestamp('2007-08-17 00:00:00') >>> pd.to_datetime('2557-08-17', format='%Y-%m-%d') # Throws Error ValueError: time data '2557-08-17' does match format specified

这是一个真正的问题,还是我做错了什么?该如何解决?

Is this a genuine issue or am I doing something wrong? How can this be fixed?

推荐答案

pandas.pydata/pandas-docs/stable/timeseries.html#timeseries-oob

以下是表示超出界限的数据的方法(从Timestamp('1677-09-22 00:12:43.145225')到Timestamp('2262-04-11 23:47:16.854775807')).

Here are ways to represent data outside of the bounds (which are from Timestamp('1677-09-22 00:12:43.145225') to Timestamp('2262-04-11 23:47:16.854775807') ).

建议在TimeStamp范围之外进行计算的方法是使用PeriodIndex.

The recommended way to do computations outside of the TimeStamp bounds is to use a PeriodIndex.

更多推荐

Python 2.7:Pandas日期时间不适用于将来的日期吗?

本文发布于:2023-11-27 11:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   不适用于   将来   时间   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!