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

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

      <legend id='PbGlh'><style id='PbGlh'><dir id='PbGlh'><q id='PbGlh'></q></dir></style></legend>
        <bdo id='PbGlh'></bdo><ul id='PbGlh'></ul>

      <tfoot id='PbGlh'></tfoot>

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

        使用python中的pandas解析年月日和小時在不同列中

        Parse dates when year month day and hour are in separate columns using pandas in python(使用python中的pandas解析年月日和小時在不同列中的日期)

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

                <bdo id='bKvrN'></bdo><ul id='bKvrN'></ul>
                • <small id='bKvrN'></small><noframes id='bKvrN'>

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

                  本文介紹了使用python中的pandas解析年月日和小時在不同列中的日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  看完之后在 YYYYMMDD 時解析日期和 HH 在 Python 中使用 pandas 在單獨的列中和使用pythonpandas 以年、日、小時、分鐘、秒格式解析 CSV

                  我仍然無法解析帶有年、月、日和小時分隔列的日期.我的數據是這樣的(第 0 列是 ID,第 1 列是年,第 2 列是月,第 3 列是天,第 4 列是小時,第 5 列是值)

                  I still am not able to parse dates with separated columns for year, month, day and hour. My data looks like this (zeroth column is ID, first is year, second is month, third is day, fourth is hour and fifth is value)

                  50136   2011    1   1   21  9792    
                  50136   2011    1   1   22  9794    
                  50136   2011    1   1   23  9796    
                  50136   2011    1   1   0   9798    
                  50136   2011    1   1   1   9799    
                  50136   2011    1   1   2   9802
                  

                  我嘗試過以下操作:df = pd.read_csv(file, parse_dates = {'date': [1, 2, 3, 4]}, , index_col='date'),但是我得到的索引不是時間戳,而是作為 unicode(?)

                  I've tried following: df = pd.read_csv(file, parse_dates = {'date': [1, 2, 3, 4]}, , index_col='date'), but then I get index not as timestamp but as unicode(?)

                  In  [17]: print df.head()
                  Out [17]:
                                   0     5
                  date                    
                  2011 1 1 21  50136  9792
                  2011 1 1 22  50136  9794
                  2011 1 1 23  50136  9796
                  2011 1 1 0   50136  9798
                  2011 1 1 1   50136  9799
                  
                  In  [18]: print df.index
                  Out [18]:
                  Index([u'2011 1 1 21', u'2011 1 1 22', u'2011 1 1 23', u'2011 1 1 0', u'2011 1 1 1', u'2011 1 1 2'], dtype=object)
                  

                  我顯然做錯了什么,但我無法弄清楚.任何建議都非常感謝.

                  I'm obviously doing something wrong, but I can't figure it out. Any advise is really appreciated.

                  推薦答案

                  如果常規方法不起作用,您總是可以退回到編寫自己的解析器.創建一個函數,它接受來自 parse_dates 的列并返回一個 datetime 并使用 date_parser 添加該函數.

                  If the regular methods dont work you can always fallback on writing your own parser. Make a function which accepts the columns from parse_dates and returns a datetime and add that functions with date_parser.

                  比如:

                  df = pd.read_csv(file, header=None, index_col='datetime', 
                                   parse_dates={'datetime': [1,2,3,4]}, 
                                   date_parser=lambda x: pd.datetime.strptime(x, '%Y %m %d %H'))
                  

                  返回:

                                           0     5
                  datetime                        
                  2011-01-01 21:00:00  50136  9792
                  2011-01-01 22:00:00  50136  9794
                  2011-01-01 23:00:00  50136  9796
                  2011-01-01 00:00:00  50136  9798
                  2011-01-01 01:00:00  50136  9799
                  2011-01-01 02:00:00  50136  9802
                  

                  如果你把它寫成普通函數而不是 lambda,也許會更清楚:

                  edit:

                  Perhaps its more clear if you write it like a normal function instead of a lambda:

                  def dt_parse(date_string):
                  
                      dt = pd.datetime.strptime(date_string, '%Y %m %d %H')
                  
                      return dt
                  

                  這篇關于使用python中的pandas解析年月日和小時在不同列中的日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)
                    <bdo id='WOw8Q'></bdo><ul id='WOw8Q'></ul>

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

                      <tfoot id='WOw8Q'></tfoot>

                          <tbody id='WOw8Q'></tbody>
                        <legend id='WOw8Q'><style id='WOw8Q'><dir id='WOw8Q'><q id='WOw8Q'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 91私密视频| 国产偷自视频区视频 | 99热在线播放 | 欧美日韩黄 | 午夜视频在线免费观看 | 一级特黄视频 | 亚洲成人免费在线观看 | 日本一本在线 | 日韩中文字幕一区 | 日本久久福利 | 国产在线观看一区 | 欧美二区三区 | 国产亚洲精品久久午夜玫瑰园 | 久久精品1 | 日韩久久网 | 亚洲高清视频一区二区 | 欧美久久国产精品 | 婷婷色成人 | 欧美日韩一区二区视频在线观看 | 中文字幕一区二区不卡 | 91一区| 亚洲成人一区 | 女生羞羞网站 | 97人澡人人添人人爽欧美 | 亚洲成人一区二区 | 国产精品大片在线观看 | 亚洲男人网 | 黄网免费看 | 国产视频精品免费 | 日本久久一区二区三区 | 99久久精品免费看国产四区 | 久久久久国产精品 | 国产1区2区3区| 国产精品99视频 | 久久久久国产精品一区 | 国产精品极品美女在线观看免费 | 黄网站在线观看 | 久久国产一区 | 国产一区二区在线播放视频 | 午夜电影福利 | 久久久久久久久久爱 |