[英]Pandas Out of Bounds timestamp work around
I am trying to write a table from one sql server to another.我正在尝试将一个表从一个 sql server 写入另一个。 There are some date values that are very far in the future (year 9000+).有一些日期值在未来很远(9000+ 年)。 Pandas throws the error:熊猫抛出错误:
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9017-11-10 00:00:00 OutOfBoundsDatetime:越界纳秒时间戳:9017-11-10 00:00:00
when trying to write or perform the pd.to_datetime() funciton on the column.尝试在列上编写或执行 pd.to_datetime() 函数时。 I would rather not convert the column to a string before writing and was hoping there is some way to handle dates so far away?我宁愿在写入之前不将列转换为字符串,并且希望有某种方法可以处理这么远的日期?
From the googling I've done, it does seem that pandas does do this by design.从我所做的谷歌搜索来看,熊猫似乎确实是有意为之。 I have to believe there is an alternative though as the limitation of no far distant dates (especially when the database can handle it fine) seems pretty significant.我不得不相信有一个替代方案,因为不远日期的限制(特别是当数据库可以很好地处理它时)似乎非常重要。
The above function treats the out of bounds by setting it to its maximum supported date上述函数通过将其设置为其最大支持日期来处理越界
def date_include(dataframe):
dataframe1=dataframe.str.split(" ", n = 1, expand = True)[0]
dataframe2=dataframe.str.split(" ", n = 1, expand = True)[1]
dataframe1=pd.to_numeric(dataframe1.str.replace('-',''),errors='coerce')
dataframe1.loc[dataframe1>22620411]=22620411
dataframe1=pd.to_datetime(dataframe1,format="%Y%m%d")
date=dataframe1.astype(str)+" "+dataframe2
return date
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.