{"id":204530,"date":"2025-05-29T09:18:23","date_gmt":"2025-05-29T01:18:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204530\/"},"modified":"2025-05-29T09:18:23","modified_gmt":"2025-05-29T01:18:23","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e4%bb%a3%e7%a0%81%e6%a0%b9%e6%8d%ae%e4%b8%80%e5%88%97%e6%95%b0%e6%8d%ae%e6%89%93%e5%ba%8f%e5%8f%b7%ef%bc%8c%e4%bd%bf%e5%85%b6%e7%9b%b8%e5%90%8c%e6%95%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204530\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Python\u4ee3\u7801\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4f7f\u5176\u76f8\u540c\u6570\u636e\u62e5\u6709\u76f8\u540c\u5e8f\u53f7\uff0c\u4e0d\u540c\u6570\u636e\u5e8f\u53f7+1\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528Python\u4ee3\u7801\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4f7f\u5176\u76f8\u540c\u6570\u636e\u62e5\u6709\u76f8\u540c\u5e8f\u53f7\uff0c\u4e0d\u540c\u6570\u636e\u5e8f\u53f7+1\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u4f7f\u7528Python\u4ee3\u7801\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4f7f\u5176\u76f8\u540c\u6570\u636e\u62e5\u6709\u76f8\u540c\u5e8f\u53f7\uff0c\u4e0d\u540c\u6570\u636e\u5e8f\u53f7+1\uff1f\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/1731196844672ff7ac805b9.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u6570\u636e\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4e0a\u4e0b\u76f8\u540c\u6570\u636e\u6253\u76f8\u540c\u5e8f\u53f7<\/strong><\/p>\n<p>\u60f3\u8981\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4e0a\u4e0b\u76f8\u540c\u6570\u636e\u6253\u76f8\u540c\u5e8f\u53f7\uff0c\u4e0d\u540c\u6570\u636e\u5e8f\u53f7+1\uff0c\u4e0b\u9762\u63d0\u4f9b\u4e86\u4e00\u79cd\u4f7f\u7528python\u4ee3\u7801\u5b9e\u73b0\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>import numpy as np\nimport pandas as pd\n\ndf = pd.dataframe({\n    'data': [11, 21, 24, 24, 24, 24, 25, 25, 26, 26, 26, 26, 23, 26, 26, 26, 26, 20, 26, 26, 26, 26],\n    'nums': 0,\n})\n\ndf['nums'] = np.cumsum(df['data'].diff() != 0)\n\nprint(df)<\/pre>\n<p>\u6267\u884c\u4ee3\u7801\u540e\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre>    data  nums\n0     11     1\n1     21     2\n2     24     3\n3     24     3\n4     24     3\n5     24     3\n6     25     4\n7     25     4\n8     26     5\n9     26     5\n10    26     5\n11    26     5\n12    23     6\n13    26     7\n14    26     7\n15    26     7\n16    26     7\n17    20     8\n18    26     9\n19    26     9\n20    26     9\n21    26     9<\/pre>\n<p>\u4ece\u7ed3\u679c\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u76f8\u540c\u7684\u6570\u5b57\u88ab\u8d4b\u4e88\u4e86\u76f8\u540c\u7684\u5e8f\u53f7\uff0c\u4e0d\u540c\u7684\u6570\u5b57\u5e8f\u53f7+1\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u4f7f\u7528Python\u4ee3\u7801\u6839\u636e\u4e00\u5217\u6570\u636e\u6253\u5e8f\u53f7\uff0c\u4f7f\u5176\u76f8\u540c\u6570\u636e\u62e5\u6709\u76f8\u540c\u5e8f\u53f7\uff0c\u4e0d\u540c\u6570\u636e\u5e8f\u53f7+1\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528Python\u4ee3\u7801\u6839\u636e\u4e00\u5217&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204530","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204530"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204530\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}