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

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

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

    1. <tfoot id='fDev9'></tfoot>
    2. <legend id='fDev9'><style id='fDev9'><dir id='fDev9'><q id='fDev9'></q></dir></style></legend>
        <bdo id='fDev9'></bdo><ul id='fDev9'></ul>

        如何使用空值將字符串轉(zhuǎn)換為日期時(shí)間 - python,

        How to convert string to datetime with nulls - python, pandas?(如何使用空值將字符串轉(zhuǎn)換為日期時(shí)間 - python,pandas?)
            • <i id='pqht4'><tr id='pqht4'><dt id='pqht4'><q id='pqht4'><span id='pqht4'><b id='pqht4'><form id='pqht4'><ins id='pqht4'></ins><ul id='pqht4'></ul><sub id='pqht4'></sub></form><legend id='pqht4'></legend><bdo id='pqht4'><pre id='pqht4'><center id='pqht4'></center></pre></bdo></b><th id='pqht4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pqht4'><tfoot id='pqht4'></tfoot><dl id='pqht4'><fieldset id='pqht4'></fieldset></dl></div>
                  <bdo id='pqht4'></bdo><ul id='pqht4'></ul>
                • <tfoot id='pqht4'></tfoot>

                    <tbody id='pqht4'></tbody>

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

                • <legend id='pqht4'><style id='pqht4'><dir id='pqht4'><q id='pqht4'></q></dir></style></legend>

                  本文介紹了如何使用空值將字符串轉(zhuǎn)換為日期時(shí)間 - python,pandas?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)包含一些日期時(shí)間(作為字符串)和一些空值作為nan"的系列:

                  I have a series with some datetimes (as strings) and some nulls as 'nan':

                  import pandas as pd, numpy as np, datetime as dt
                  df = pd.DataFrame({'Date':['2014-10-20 10:44:31', '2014-10-23 09:33:46', 'nan', '2014-10-01 09:38:45']})
                  

                  我正在嘗試將這些轉(zhuǎn)換為日期時(shí)間:

                  I'm trying to convert these to datetime:

                  df['Date'] = df['Date'].apply(lambda x: dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S'))
                  

                  但我得到了錯(cuò)誤:

                  time data 'nan' does not match format '%Y-%m-%d %H:%M:%S'
                  

                  所以我試著把這些變成實(shí)際的空值:

                  So I try to turn these into actual nulls:

                  df.ix[df['Date'] == 'nan', 'Date'] = np.NaN
                  

                  然后重復(fù):

                  df['Date'] = df['Date'].apply(lambda x: dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S'))
                  

                  然后我得到錯(cuò)誤:

                  必須是字符串,不能是浮點(diǎn)數(shù)

                  must be string, not float

                  解決這個(gè)問題的最快方法是什么?

                  What is the quickest way to solve this problem?

                  推薦答案

                  只要使用to_datetime 并設(shè)置 errors='coerce' 來處理 duff 數(shù)據(jù):

                  Just use to_datetime and set errors='coerce' to handle duff data:

                  In [321]:
                  
                  df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
                  df
                  Out[321]:
                                   Date
                  0 2014-10-20 10:44:31
                  1 2014-10-23 09:33:46
                  2                 NaT
                  3 2014-10-01 09:38:45
                  
                  In [322]:
                  
                  df.info()
                  <class 'pandas.core.frame.DataFrame'>
                  Int64Index: 4 entries, 0 to 3
                  Data columns (total 1 columns):
                  Date    3 non-null datetime64[ns]
                  dtypes: datetime64[ns](1)
                  memory usage: 64.0 bytes
                  

                  調(diào)用 strptime 的問題是如果字符串或 dtype 不正確會(huì)引發(fā)錯(cuò)誤.

                  the problem with calling strptime is that it will raise an error if the string, or dtype is incorrect.

                  如果你這樣做了,那么它會(huì)起作用:

                  If you did this then it would work:

                  In [324]:
                  
                  def func(x):
                      try:
                          return dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
                      except:
                          return pd.NaT
                  
                  df['Date'].apply(func)
                  Out[324]:
                  0   2014-10-20 10:44:31
                  1   2014-10-23 09:33:46
                  2                   NaT
                  3   2014-10-01 09:38:45
                  Name: Date, dtype: datetime64[ns]
                  

                  但是使用內(nèi)置的 to_datetime 而不是調(diào)用 apply 會(huì)更快,這實(shí)際上只是循環(huán)您的系列.

                  but it will be faster to use the inbuilt to_datetime rather than call apply which essentially just loops over your series.

                  時(shí)間

                  In [326]:
                  
                  %timeit pd.to_datetime(df['Date'], errors='coerce')
                  %timeit df['Date'].apply(func)
                  10000 loops, best of 3: 65.8 μs per loop
                  10000 loops, best of 3: 186 μs per loop
                  

                  我們?cè)谶@里看到使用 to_datetime 的速度提高了 3 倍.

                  We see here that using to_datetime is 3X faster.

                  這篇關(guān)于如何使用空值將字符串轉(zhuǎn)換為日期時(shí)間 - python,pandas?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動(dòng)后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動(dòng)時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)

                    • <bdo id='lj56G'></bdo><ul id='lj56G'></ul>

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

                          <tbody id='lj56G'></tbody>
                        <tfoot id='lj56G'></tfoot>
                      1. <i id='lj56G'><tr id='lj56G'><dt id='lj56G'><q id='lj56G'><span id='lj56G'><b id='lj56G'><form id='lj56G'><ins id='lj56G'></ins><ul id='lj56G'></ul><sub id='lj56G'></sub></form><legend id='lj56G'></legend><bdo id='lj56G'><pre id='lj56G'><center id='lj56G'></center></pre></bdo></b><th id='lj56G'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lj56G'><tfoot id='lj56G'></tfoot><dl id='lj56G'><fieldset id='lj56G'></fieldset></dl></div>
                            <legend id='lj56G'><style id='lj56G'><dir id='lj56G'><q id='lj56G'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 欧美成人一区二区三区 | 久久99国产精品 | 国产中文视频 | 黄色国产在线播放 | 成人在线视频免费播放 | 日韩在线不卡视频 | 欧美一级片在线观看 | 色欧美综合 | 大学生a级毛片免费视频 | 日本黄色的视频 | 精品国产一区二区三区性色 | 特黄视频 | 黄网站免费入口 | 久久久久久久久国产 | 精品无码久久久久久国产 | 日本一二三区在线观看 | 祝你幸福电影在线观看 | 亚洲a一区 | 欧美日韩淫片 | 精品少妇一区二区三区日产乱码 | 欧美成人免费电影 | 亚洲一区二区久久 | 国产日韩一区二区三免费高清 | 国产一区精品 | 午夜精品久久久久久久99黑人 | 天天操夜夜看 | 亚洲天堂网站 | 久久久久av | 精品在线观看一区二区 | 成人影院在线 | 一区二区不卡 | 九九综合| 精品一区二区三区四区外站 | 日韩高清中文字幕 | 欧美激情久久久久久 | 亚洲精品乱码久久久久久按摩观 | 日韩视频成人 | 亚洲狠狠| 国产精品久久久久一区二区三区 | 欧美性精品 | 日本午夜视频 |