pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="y736r8c" 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="e2jar1z" 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="pxagu3j" 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>

                            主站蜘蛛池模板: 自动部分收集器,进口无油隔膜真空泵,SPME固相微萃取头-上海楚定分析仪器有限公司 | 软文世界-软文推广-软文营销-新闻稿发布-一站式软文自助发稿平台 | 金现代信息产业股份有限公司--数字化解决方案供应商 | 臭氧实验装置_实验室臭氧发生器-北京同林臭氧装置网 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 北京遮阳网-防尘盖土网-盖土草坪-迷彩网-防尘网生产厂家-京兴科技 | 磁力抛光机_磁力研磨机_磁力去毛刺机-冠古设备厂家|维修|租赁【官网】 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 高精度-恒温冷水机-螺杆式冰水机-蒸发冷冷水机-北京蓝海神骏科技有限公司 | 生物风-销售载体,基因,质粒,ATCC细胞,ATCC菌株等,欢迎购买-百风生物 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 蓝莓施肥机,智能施肥机,自动施肥机,水肥一体化项目,水肥一体机厂家,小型施肥机,圣大节水,滴灌施工方案,山东圣大节水科技有限公司官网17864474793 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 北京软件开发_软件开发公司_北京软件公司-北京宜天信达软件开发公司 | 广州展览制作工厂—[优简]直营展台制作工厂_展会搭建资质齐全 | 学叉车培训|叉车证报名|叉车查询|叉车证怎么考-工程机械培训网 | 尼龙PA610树脂,尼龙PA612树脂,尼龙PA1010树脂,透明尼龙-谷骐科技【官网】 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 披萨石_披萨盘_电器家电隔热绵加工定制_佛山市南海区西樵南方综合保温材料厂 | 精密光学实验平台-红外粉末压片机模具-天津博君 | 压滤机-洗沙泥浆处理-压泥机-山东创新华一环境工程有限公司 | 无硅导热垫片-碳纤维导热垫片-导热相变材料厂家-东莞市盛元新材料科技有限公司 | 权威废金属|废塑料|废纸|废铜|废钢价格|再生资源回收行情报价中心-中废网 | 反渗透水处理设备|工业零排放|水厂设备|软化水设备|海南净水设备--海南水处理设备厂家 | 镀锌角钢_槽钢_扁钢_圆钢_方矩管厂家_镀锌花纹板-海邦钢铁(天津)有限公司 | BESWICK球阀,BESWICK接头,BURKERT膜片阀,美国SEL继电器-东莞市广联自动化科技有限公司 | MOOG伺服阀维修,ATOS比例流量阀维修,伺服阀维修-上海纽顿液压设备有限公司 | 常州企业采购平台_常州MRO采购公司_常州米孚机电设备有限公司 | 高效复合碳源-多核碳源生产厂家-污水处理反硝化菌种一长隆科技库巴鲁 | 道达尔润滑油-食品级润滑油-道达尔导热油-合成导热油,深圳道达尔代理商合-深圳浩方正大官网 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | nalgene洗瓶,nalgene量筒,nalgene窄口瓶,nalgene放水口大瓶,浙江省nalgene代理-杭州雷琪实验器材有限公司 | China plate rolling machine manufacturer,cone rolling machine-Saint Fighter | 有声小说,听书,听小说资源库-听世界网 | 蔬菜清洗机_环速洗菜机_异物去除清洗机_蔬菜清洗机_商用洗菜机 - 环速科技有限公司 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 超声波气象站_防爆气象站_空气质量监测站_负氧离子检测仪-风途物联网 | 液压压力机,液压折弯机,液压剪板机,模锻液压机-鲁南新力机床有限公司 | 市政路灯_厂家-淄博信达电力科技有限公司|