久久久久久久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 按日期列出分組的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  假設(shè)我有一個(gè)如下所示的列表:

                  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)]
                  

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

                  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)
                  

                  第二個(gè)元素是監(jiān)控值.但是,每天可能有多個(gè)記錄.例如,datetime.datetime(2013, 8, 9..) 上有兩條記錄,它們有兩個(gè)不同的值 2055 和 2050.我想要的是實(shí)際上每天的最大值.所以在這種情況下.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 中是否有一種方便的方法可以做到這一點(diǎn).類似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 語句只是為了展示這個(gè)想法,我絕對想要一個(gè) 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),
                   ...
                  ]
                  

                  注意:假設(shè)記錄已排序.如果沒有,您應(yīng)該先按日期對它們進(jìn)行排序.

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

                  這篇關(guān)于Python 按日期列出分組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個(gè)模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點(diǎn)包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復(fù)導(dǎo)入頂級名稱的情況下構(gòu)造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(分發(fā)帶有已編譯動(dòng)態(tài)共享庫的 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>

                            主站蜘蛛池模板: 欧美在线视频免费 | 九九热在线视频观看 | 成年人网站在线免费观看 | 国产探花视频在线观看 | 国产免费自拍视频 | 插少妇 | 国产一区二区三区在线 | 欧美日韩精品一区二区 | 国产精品久久久久久久久久久久午夜片 | 国产精品永久久久久久久久久 | 免费一级片 | 天天干夜夜欢 | 国产网址| 欧美日韩一区二区三区视频 | 日产毛片| 国产精品久久久久久久久久 | 中文字幕久久久 | 国产aⅴ爽av久久久久成人 | 日本免费在线观看视频 | 欧美日韩亚洲另类 | 成人午夜又粗又硬又大 | 蜜桃色999 | 久久久久久艹 | 无遮挡在线观看 | av黄色网| 四虎三级| 日韩av中文字幕在线播放 | 青青草精品视频 | 久久久久久99精品久久久 | 精品一区二区三区免费 | 日本黄a三级三级三级 | 久久亚洲成人 | 欧美一区二区在线播放 | 国产日韩精品视频 | 国产成人免费视频 | 久久久久久黄色 | 性做久久久久久久免费看 | 亚洲免费视频一区 | 国产乡下妇女做爰视频 | 九九热精品在线 | 美日韩一区 |