{"id":14,"date":"2026-11-08T13:15:38","date_gmt":"2026-11-08T13:15:38","guid":{"rendered":"http:\/\/blog.antpython.net\/?p=14"},"modified":"2026-11-08T13:15:38","modified_gmt":"2026-11-08T13:15:38","slug":"%e6%97%b6%e9%97%b4%e5%ba%8f%e5%88%97%e5%9f%ba%e7%a1%80%ef%bc%9a%e6%97%a5%e6%9c%9f%e7%b4%a2%e5%bc%95%e3%80%81%e9%87%8d%e9%87%87%e6%a0%b7%e4%b8%8e%e6%bb%9a%e5%8a%a8%e7%aa%97%e5%8f%a3","status":"publish","type":"post","link":"http:\/\/blog.antpython.net\/?p=14","title":{"rendered":"\u65f6\u95f4\u5e8f\u5217\u57fa\u7840\uff1a\u65e5\u671f\u7d22\u5f15\u3001\u91cd\u91c7\u6837\u4e0e\u6eda\u52a8\u7a97\u53e3"},"content":{"rendered":"<p>\u8ba2\u5355\u3001\u6d41\u91cf\u3001\u4f20\u611f\u5668\u6570\u636e\u90fd\u5e26\u65f6\u95f4\u3002\u638c\u63e1\u65e5\u671f\u7d22\u5f15\u3001\u91cd\u91c7\u6837\u3001\u6eda\u52a8\u7edf\u8ba1\uff0c\u4f60\u5c31\u80fd\u505a\u8d8b\u52bf\u3001\u73af\u6bd4\u548c\u7b80\u5355\u5f02\u5e38\u53d1\u73b0\u3002<\/p>\n<h2>\u53d8\u6210\u65f6\u95f4\u7d22\u5f15<\/h2>\n<pre><code>import pandas as pd\n\ndf[\"order_date\"] = pd.to_datetime(df[\"order_date\"])\nts = df.set_index(\"order_date\").sort_index()\nprint(ts.loc[\"2026-01\":\"2026-03\"])  # \u6309\u6708\u4efd\u5207\u7247\n<\/code><\/pre>\n<h2>\u91cd\u91c7\u6837\uff1a\u65e5 \u2192 \u5468\/\u6708<\/h2>\n<pre><code>daily = ts[\"amount\"].resample(\"D\").sum()\nweekly = ts[\"amount\"].resample(\"W\").sum()\nmonthly = ts[\"amount\"].resample(\"ME\").sum()\n<\/code><\/pre>\n<h2>\u6eda\u52a8\u7a97\u53e3\uff1a\u5e73\u6ed1\u566a\u58f0<\/h2>\n<pre><code># 7 \u65e5\u6ed1\u52a8\u5747\u503c\nsmooth = daily.rolling(window=7, min_periods=1).mean()\n\n# \u540c\u65f6\u770b\u5747\u503c\u548c\u6807\u51c6\u5dee\uff0c\u4fbf\u4e8e\u53d1\u73b0\u5f02\u5e38\u6ce2\u52a8\nroll = daily.rolling(7).agg([\"mean\", \"std\"])\n<\/code><\/pre>\n<h2>\u73af\u6bd4 \/ \u540c\u6bd4<\/h2>\n<pre><code>mom = monthly.pct_change()          # \u6708\u73af\u6bd4\nyoy = monthly.pct_change(periods=12) # \u6708\u540c\u6bd4\uff08\u9700\u8db3\u591f\u957f\u5386\u53f2\uff09\n<\/code><\/pre>\n<h2>\u5c0f\u6848\u4f8b\uff1a\u627e\u51fa\u9500\u91cf\u5f02\u5e38\u65e5<\/h2>\n<pre><code>mu = daily.rolling(14).mean()\nsigma = daily.rolling(14).std()\nanomaly = daily[(daily - mu).abs() &gt; 2 * sigma]\nprint(anomaly)\n<\/code><\/pre>\n<h2>\u6ce8\u610f\u65f6\u533a\u4e0e\u7f3a\u5931\u65e5\u671f<\/h2>\n<pre><code># \u8865\u9f50\u6ca1\u6709\u4e0b\u5355\u7684\u65e5\u671f\uff0c\u91d1\u989d\u586b 0\nfull = daily.asfreq(\"D\").fillna(0)\n<\/code><\/pre>\n<p>\u5206\u6790\u8d8b\u52bf\u524d\u5148\u95ee\uff1a\u65f6\u95f4\u662f\u5426\u5355\u8c03\u3001\u6709\u6ca1\u6709\u7f3a\u53e3\u3001\u65f6\u533a\u662f\u5426\u7edf\u4e00\u3002\u8fd9\u4e09\u4ef6\u4e8b\u6bd4\u7b97\u6cd5\u66f4\u5f71\u54cd\u7ed3\u8bba\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ba2\u5355\u3001\u6d41\u91cf\u3001\u4f20\u611f\u5668\u6570\u636e\u90fd\u5e26\u65f6\u95f4\u3002\u638c\u63e1\u65e5\u671f\u7d22\u5f15\u3001\u91cd\u91c7\u6837\u3001\u6eda\u52a8\u7edf\u8ba1\uff0c\u4f60\u5c31\u80fd\u505a\u8d8b\u52bf\u3001\u73af\u6bd4\u548c\u7b80\u5355\u5f02\u5e38\u53d1\u73b0\u3002 \u53d8\u6210\u65f6\u95f4\u7d22 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-pandas-analysis"],"_links":{"self":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":0,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}