Python 2.7:Pandas日期时间不适用于将来的日期吗? [英] Python 2.7: Pandas datetime does not work for future dates?

查看:80
本文介绍了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?

推荐答案

以下是表示超出界限的数据的方法(从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日期时间不适用于将来的日期吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆