久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='FmkBb'></tfoot>

    <small id='FmkBb'></small><noframes id='FmkBb'>

      <i id='FmkBb'><tr id='FmkBb'><dt id='FmkBb'><q id='FmkBb'><span id='FmkBb'><b id='FmkBb'><form id='FmkBb'><ins id='FmkBb'></ins><ul id='FmkBb'></ul><sub id='FmkBb'></sub></form><legend id='FmkBb'></legend><bdo id='FmkBb'><pre id='FmkBb'><center id='FmkBb'></center></pre></bdo></b><th id='FmkBb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FmkBb'><tfoot id='FmkBb'></tfoot><dl id='FmkBb'><fieldset id='FmkBb'></fieldset></dl></div>
      • <bdo id='FmkBb'></bdo><ul id='FmkBb'></ul>
      <legend id='FmkBb'><style id='FmkBb'><dir id='FmkBb'><q id='FmkBb'></q></dir></style></legend>
    1. 對于 1970-01-01 之前的日期,Windows 上 datetime time

      Workaround for datetime timestamp() on Windows for dates preceeding 1970-01-01(對于 1970-01-01 之前的日期,Windows 上 datetime timestamp() 的解決方法)
      <i id='jimT2'><tr id='jimT2'><dt id='jimT2'><q id='jimT2'><span id='jimT2'><b id='jimT2'><form id='jimT2'><ins id='jimT2'></ins><ul id='jimT2'></ul><sub id='jimT2'></sub></form><legend id='jimT2'></legend><bdo id='jimT2'><pre id='jimT2'><center id='jimT2'></center></pre></bdo></b><th id='jimT2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jimT2'><tfoot id='jimT2'></tfoot><dl id='jimT2'><fieldset id='jimT2'></fieldset></dl></div>

      <small id='jimT2'></small><noframes id='jimT2'>

        <bdo id='jimT2'></bdo><ul id='jimT2'></ul>

            <legend id='jimT2'><style id='jimT2'><dir id='jimT2'><q id='jimT2'></q></dir></style></legend>
            <tfoot id='jimT2'></tfoot>

                  <tbody id='jimT2'></tbody>

                本文介紹了對于 1970-01-01 之前的日期,Windows 上 datetime timestamp() 的解決方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我目前正在嘗試通過將日期轉換為時間戳來在數據集中生成數字特征.如果在 Mac 上運行,它可以完美運行,在 Windows 上它會拋出:

                I am currently trying to generate numerical features in a dataset by converting the dates to timestamps. If run on Mac, it works flawlessly, on Windows it throws an:

                OS Error: [Errno 22] Invalid argument
                

                這可能是由于 Windows 不支持 unix 時間戳1970-01-01 之前.我的日期從 1955 年開始.這是我的代碼:

                which is probably due to Windows not supporting unix timestamps from before 1970-01-01. I have dates from 1955 upwards. Here is my code:

                import time
                import datetime
                
                current_timestamp = time.time()
                df.loc[:, "FEATURE_num"] = df["FEATURE"].apply(lambda d: datetime.datetime.strptime(d, '%Y-%m-%d').timestamp() if isinstance(d, str) else current_timestamp)
                

                我在某處看到有人建議使用 datetime.timedelta(),但我不知道如何集成它.

                I somewhere saw suggested to maybe use datetime.timedelta(), but I couldn't figure out how to integrate it.

                推薦答案

                你可以通過(隱式)使用 datetime.timedelta 計算一個公歷"時間戳適用于從 1582 年 10 月 15 日到現在(或您想使用的其他紀元")的日期.

                You could do it by (implicitly) using datetime.timedelta to calculate a "Gregorian" timestamp that would be valid for dates from 1582-Oct-15 to the present (or some other "epoch" you would like to use).

                正如函數的文檔字符串所示,默認情況下,日期字符串將使用 '%Y-%m-%d' strptime-like 格式字符串參數,但可以覆蓋.

                As the function's docstring indicates, date strings will, by default, be parsed using a '%Y-%m-%d' strptime-like format string parameter, but that can be overridden.

                from datetime import datetime
                
                
                GREGORIAN_EPOCH = datetime.strptime('1582-10-15', '%Y-%m-%d')
                
                
                def gregorian_timestamp(date, format='%Y-%m-%d'):
                    """ Calculate timestamp using start of Gregorian calender as epoch.
                
                        The date parameter can be either a string or a datetime.datetime
                        object. Strings will be parsed using the '%Y-%m-%d' format by default
                        unless a different one is specfied via the optional format parameter.
                    """
                    try:
                        date = datetime.strptime(date, format)
                    except TypeError:
                        pass
                    return (date - GREGORIAN_EPOCH).total_seconds()  # The timedelta in seconds.
                
                
                if __name__ == '__main__':
                
                    current_date = datetime.now()
                    timestamp = gregorian_timestamp(current_date)
                    print('gregorian timestamp:', timestamp)  # -> gregorian timestamp: 13768250461.136208
                
                    timestamp = gregorian_timestamp('1970-01-01')
                    print('gregorian timestamp:', timestamp)  # -> gregorian timestamp: 12219292800.0
                
                    timestamp = gregorian_timestamp('1955-02-28')
                    print('gregorian timestamp:', timestamp)  # -> gregorian timestamp: 11750918400.0
                
                    timestamp = gregorian_timestamp('1582-10-15')
                    print('gregorian timestamp:', timestamp)  # -> gregorian timestamp: 0.0
                

                這篇關于對于 1970-01-01 之前的日期,Windows 上 datetime timestamp() 的解決方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                How to refresh sys.path?(如何刷新 sys.path?)
                Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                <small id='fwnbn'></small><noframes id='fwnbn'>

                1. <legend id='fwnbn'><style id='fwnbn'><dir id='fwnbn'><q id='fwnbn'></q></dir></style></legend>

                        <bdo id='fwnbn'></bdo><ul id='fwnbn'></ul>
                          <tbody id='fwnbn'></tbody>
                        <tfoot id='fwnbn'></tfoot>
                        • <i id='fwnbn'><tr id='fwnbn'><dt id='fwnbn'><q id='fwnbn'><span id='fwnbn'><b id='fwnbn'><form id='fwnbn'><ins id='fwnbn'></ins><ul id='fwnbn'></ul><sub id='fwnbn'></sub></form><legend id='fwnbn'></legend><bdo id='fwnbn'><pre id='fwnbn'><center id='fwnbn'></center></pre></bdo></b><th id='fwnbn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fwnbn'><tfoot id='fwnbn'></tfoot><dl id='fwnbn'><fieldset id='fwnbn'></fieldset></dl></div>

                          主站蜘蛛池模板: 99亚洲综合 | 亚洲一区国产 | 日韩在线一区二区三区 | 日韩av资源站 | 免费在线视频一区二区 | 久久综合久久久 | 午夜精品久久久久久久久久久久久 | 欧美日本一区 | 欧美一级欧美一级在线播放 | 天天摸天天干 | 亚州中文字幕 | 在线日韩中文字幕 | 免费观看一级特黄欧美大片 | 成年人黄色一级毛片 | 久久成人免费视频 | 亚洲天堂999 | 欧洲一区二区在线 | 牛牛热在线视频 | 精品美女视频在线观看免费软件 | 九九精品网 | 成人不卡一区二区 | 国产在线一区二区三区 | 91在线一区 | 免费观看一区二区三区毛片 | 香蕉超碰 | 国产精品久久久久aaaa九色 | 国产小视频在线 | 黄色一级免费看 | 国产精品美女久久久av超清 | wwwxx在线观看 | 欧美精品久久 | 国产精品一区二区三区久久久 | 高清视频一区二区三区 | 国产91久久精品一区二区 | av在线免费看网址 | 免费看黄色国产 | 日本一二三区电影 | 激情五月婷婷丁香 | 久久精品亚洲精品 | 国户精品久久久久久久久久久不卡 | 欧美午夜一区 |