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

  • <small id='3Kjbu'></small><noframes id='3Kjbu'>

        <tfoot id='3Kjbu'></tfoot>
          <bdo id='3Kjbu'></bdo><ul id='3Kjbu'></ul>
      1. <legend id='3Kjbu'><style id='3Kjbu'><dir id='3Kjbu'><q id='3Kjbu'></q></dir></style></legend>
        <i id='3Kjbu'><tr id='3Kjbu'><dt id='3Kjbu'><q id='3Kjbu'><span id='3Kjbu'><b id='3Kjbu'><form id='3Kjbu'><ins id='3Kjbu'></ins><ul id='3Kjbu'></ul><sub id='3Kjbu'></sub></form><legend id='3Kjbu'></legend><bdo id='3Kjbu'><pre id='3Kjbu'><center id='3Kjbu'></center></pre></bdo></b><th id='3Kjbu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3Kjbu'><tfoot id='3Kjbu'></tfoot><dl id='3Kjbu'><fieldset id='3Kjbu'></fieldset></dl></div>
      2. Python 按日期列出分組

        Python List Group by Date(Python 按日期列出分組)

            <tfoot id='ikWrg'></tfoot>
          1. <small id='ikWrg'></small><noframes id='ikWrg'>

              <bdo id='ikWrg'></bdo><ul id='ikWrg'></ul>
                <tbody id='ikWrg'></tbody>

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

              • <legend id='ikWrg'><style id='ikWrg'><dir id='ikWrg'><q id='ikWrg'></q></dir></style></legend>
                  本文介紹了Python 按日期列出分組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  假設我有一個如下所示的列表:

                  Say I have a list looks like this:

                  [(datetime.datetime(2013, 8, 8, 1, 20, 15), 2060), (datetime.datetime(2013, 8, 9, 1, 6, 14), 2055), (datetime.datetime(2013, 8, 9, 1, 21, 1), 2050), (datetime.datetime(2013, 8, 10, 1, 5, 49), 2050), (datetime.datetime(2013, 8, 10, 1, 19, 51), 2050), (datetime.datetime(2013, 8, 11, 2, 4, 53), 2050), (datetime.datetime(2013, 8, 12, 0, 29, 45), 2050), (datetime.datetime(2013, 8, 12, 0, 44, 13), 2050), (datetime.datetime(2013, 8, 13, 0, 34, 13), 2050), (datetime.datetime(2013, 8, 13, 0, 47, 29), 2050), (datetime.datetime(2013, 8, 14, 1, 30, 39), 2050), (datetime.datetime(2013, 8, 14, 1, 33, 51), 2050), (datetime.datetime(2013, 8, 15, 0, 41, 1), 2050), (datetime.datetime(2013, 8, 15, 0, 54, 45), 2050), (datetime.datetime(2013, 8, 16, 0, 29, 57), 1950), (datetime.datetime(2013, 8, 16, 0, 43, 11), 1950), (datetime.datetime(2013, 8, 17, 0, 27, 4), 1950), (datetime.datetime(2013, 8, 17, 0, 42, 30), 1950), (datetime.datetime(2013, 8, 18, 0, 26, 26), 1950), (datetime.datetime(2013, 8, 18, 0, 43, 11), 1950), (datetime.datetime(2013, 8, 19, 0, 41, 49), 1950), (datetime.datetime(2013, 8, 20, 1, 10, 23), 1950), (datetime.datetime(2013, 8, 20, 1, 23, 44), 1950), (datetime.datetime(2013, 8, 21, 0, 47, 25), 1950), (datetime.datetime(2013, 8, 21, 1, 0, 12), 1950), (datetime.datetime(2013, 8, 22, 0, 45, 21), 1950), (datetime.datetime(2013, 8, 22, 1, 4, 33), 1950), (datetime.datetime(2013, 8, 23, 0, 51, 27), 1950), (datetime.datetime(2013, 8, 23, 1, 6, 36), 1950), (datetime.datetime(2013, 8, 24, 0, 41, 3), 1950), (datetime.datetime(2013, 8, 24, 0, 53, 14), 1950), (datetime.datetime(2013, 8, 25, 0, 29, 24), 1950), (datetime.datetime(2013, 8, 25, 0, 42, 40), 1950), (datetime.datetime(2013, 8, 26, 0, 28, 13), 1950), (datetime.datetime(2013, 8, 26, 0, 43, 30), 1950), (datetime.datetime(2013, 8, 27, 0, 30, 1), 1950), (datetime.datetime(2013, 8, 27, 0, 43, 43), 1950), (datetime.datetime(2013, 8, 28, 0, 33, 19), 1950), (datetime.datetime(2013, 8, 28, 0, 49, 11), 1950), (datetime.datetime(2013, 8, 29, 0, 26, 49), 1950), (datetime.datetime(2013, 8, 29, 0, 41, 21), 1950), (datetime.datetime(2013, 8, 30, 0, 26, 13), 1950), (datetime.datetime(2013, 8, 30, 0, 42, 9), 1950), (datetime.datetime(2013, 8, 31, 0, 23, 40), 1950), (datetime.datetime(2013, 8, 31, 0, 39, 49), 1950), (datetime.datetime(2013, 9, 1, 0, 22, 2), 1950), (datetime.datetime(2013, 9, 1, 0, 38, 16), 1950), (datetime.datetime(2013, 9, 2, 0, 21, 2), 1950), (datetime.datetime(2013, 9, 2, 0, 36, 19), 1950), (datetime.datetime(2013, 9, 3, 0, 22, 16), 1950), (datetime.datetime(2013, 9, 3, 0, 39, 2), 1900)]
                  

                  很明顯,您可以看到這是一個元組列表,每個元組中的第一個元素是一個時間戳.已采用良好格式,由以下人員生成:

                  clearly you could see that this is a list of tuple and the first element in each tuple is a timestamp. Already in good format, generated by:

                  datetime.strptime(record[0], timeFormat)
                  

                  第二個元素是監控值.但是,每天可能有多個記錄.例如,datetime.datetime(2013, 8, 9..) 上有兩條記錄,它們有兩個不同的值 2055 和 2050.我想要的是實際上每天的最大值.所以在這種情況下.2055 將是 (2013, 8, 9) 的唯一記錄.

                  And the second element is the monitoring value. However, there might be multiple records in each day. For example, there are two records on datetime.datetime(2013, 8, 9..), which have two different values 2055 and 2050. What I want is the actually the maximum in each day. So in this case. 2055 would be the only records for (2013, 8, 9).

                  我想知道 Python 中是否有一種方便的方法可以做到這一點.類似mysql的東西:

                  I am wondering would there be a handy way in Python to do that. Some thing similar like mysql:

                  select 
                      date(timestamp), 
                      max(value)
                  from table 
                  group by date(timestamp)
                  

                  mysql 語句只是為了展示這個想法,我絕對想要一個 python 解決方案.

                  The mysql statement is just to show the idea and I definitely want a python solution.

                  推薦答案

                  使用 itertools.groupby:

                  >>> records = [(datetime.datetime(2013, 8, 8, 1, 20, 15), 2060), ....]
                  >>> import itertools
                  >>> [(dt, max(v for d, v in grp)) for dt, grp in itertools.groupby(records, key=lambda x: x[0].date())]
                  [(datetime.date(2013, 8, 8), 2060),
                   (datetime.date(2013, 8, 9), 2055),
                   (datetime.date(2013, 8, 10), 2050),
                   ...
                  ]
                  

                  注意:假設記錄已排序.如果沒有,您應該先按日期對它們進行排序.

                  NOTE: assumed that the records are sorted. If not, you should sort them first by dates.

                  這篇關于Python 按日期列出分組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='K05et'></bdo><ul id='K05et'></ul>
                        <tbody id='K05et'></tbody>

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

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

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

                            主站蜘蛛池模板: 国产目拍亚洲精品99久久精品 | 国产成人在线一区二区 | 日韩一级| 午夜在线观看视频 | 国产成人精品av | 欧美一区二区在线观看 | 久久综合九色综合欧美狠狠 | 亚洲欧美一区二区三区视频 | 在线观看国产视频 | 日韩中文一区 | 天天干精品 | 日韩在线视频免费观看 | 欧美一级欧美一级在线播放 | 亚洲精品视频在线 | 小川阿佐美pgd-606在线 | 久久国产精品无码网站 | 一区视频在线免费观看 | 男女羞羞视频在线 | 手机看片在线播放 | 国产精品欧美大片 | 99久久精品免费看国产小宝寻花 | 成人午夜精品 | 亚洲精品成人网 | 国产精品久久久久一区二区 | 国产伦精品 | www.日韩 | 成人在线免费电影 | 97伦理电影 | 欧美日韩在线视频一区 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 综合另类 | 久久久久久久久久一区二区 | 国色天香综合网 | 亚洲精品久久久一区二区三区 | 午夜三级视频 | 国产精品视频播放 | 日韩精品视频在线 | 久久久.com | 国产亚洲成av人在线观看导航 | 亚洲欧美另类在线 | 欧美日韩三级 |