[英]Python shows me an Error (Out of Bounds) when running the DateTime
I am trying to change the columns 'check in' and 'check out' to Datetime.我正在尝试将“签入”和“签出”列更改为日期时间。 When I run the code below I get the error message 'Out of bounds nanosecond' (picture attached as well).当我运行下面的代码时,我收到错误消息“越界纳秒”(附上图片)。 Can anybody help me, how I can get rid of this problem please?任何人都可以帮助我,我该如何摆脱这个问题?
Thank you in advance!先感谢您!
expedia2013_2014["srch_co"] = pd.to_datetime(expedia2013_2014["srch_co"])
expedia2013_2014["srch_ci"] = pd.to_datetime(expedia2013_2014["srch_ci"])
Variables of Timestamp type can hold dates roughly from years in range (1677, 2262). Timestamp类型的变量可以保存大致从年份 (1677, 2262) 开始的日期。 You attempt to convert date from year 2557 , so it is out of range.您尝试从2557年开始转换日期,因此它超出了范围。 You have to use other date format.您必须使用其他日期格式。
One of possible options: If you have the source date as a string , eg src='2557-08-17'
, you can run:可能的选项之一:如果源日期为字符串,例如src='2557-08-17'
,则可以运行:
result = datetime.datetime.strptime(src, '%Y-%m-%d')
If you have a DataFrame with source column named Dat (as string), you can convert it running:如果您有一个名为Dat (作为字符串)的源列的 DataFrame,您可以将其转换为运行:
df.Dat = df.Dat.apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d').date())
When you print df , it is printed just the same way, but when you read it calling df.loc[some_index,'Dat']
, the result will be datetime.date(2557, 8, 17)
.当您打印df 时,它的打印方式相同,但是当您调用df.loc[some_index,'Dat']
读取它时,结果将是datetime.date(2557, 8, 17)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.