简体   繁体   English

熊猫越界时间戳解决方法

[英]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.

相关问题 如何解决Python Pandas DataFrame的“ Outbounds nanosecond timestamp”错误? - How to work around Python Pandas DataFrame's “Out of bounds nanosecond timestamp” error? 熊猫,处理“超出时间戳范围……” - Pandas, Handling “Out of bounds timestamp…” 长数据框的Python Pandas超出日期时间时间戳错误 - Python Pandas out of bounds datetime timestamp error for long dataframe 超出范围的纳秒级时间戳 - Out of bounds nanosecond timestamp Python Pandas to_datetime pandas.datetime的出纳秒时间戳 - Python Pandas to_datetime Out of bounds nanosecond timestamp on a pandas.datetime OutOfBoundsDatetime:越界纳秒时间戳 - OutOfBoundsDatetime: Out of bounds nanosecond timestamp 如何在方法'pandas.read_sql()'中处理时间戳的'越界'错误 - How to deal with 'out-of-bounds' error for timestamp in the method 'pandas.read_sql()' 将 Pandas df 写入 Pyarrow Parquet 表会导致“越界”时间戳问题 - Writing Pandas df to Pyarrow Parquet table results in 'out of bounds' timestamp issue 偏移量前滚后加上一个月偏移量后的熊猫超出纳秒时间戳 - pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset 从 CSV 导入时转换日期,OutOfBoundsDatetime:超出范围纳秒时间戳。 Pandas - Converting dates when importing from CSV, OutOfBoundsDatetime: Out of bounds nanosecond timestamp. Pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM