久久久久久久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>

                            主站蜘蛛池模板: 人人草人人草 | 最新免费黄色网址 | 狠狠干狠狠操 | 草逼视频免费看 | 欧美精品成人 | a毛片在线观看 | 性做久久久久久 | 夜夜嗨av一区二区三区网页 | 精品一区二区三区在线观看 | 中文字幕av在线播放 | 欧美伊人久久 | 日韩精品福利 | 日韩av在线一区二区 | 国产日韩视频 | 亚洲第一毛片 | 国产理论在线 | 中文在线字幕 | 天海翼一区二区 | 日韩久久综合 | 日b免费视频 | 国产精品一区一区三区 | 国产三级做爰高清在线 | 国产精品欧美激情 | 色网站在线 | 97超碰在线播放 | 99热在线观看 | 精品久久久久久久 | 久久久夜色精品 | 欧美日韩免费在线观看 | 成人h片在线观看 | 亚洲视频免费观看 | 日韩一区二区三区在线播放 | 免费日韩av | 欧美日韩小视频 | 天天干狠狠操 | 国产日韩欧美日韩大片 | 一级黄色在线观看 | 国产二区三区 | 97国产精品视频 | 伊人久久在线 | 婷婷六月天 |