{"id":187,"date":"2025-05-31T17:55:29","date_gmt":"2025-06-04T10:09:28","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=187"},"modified":"2025-06-04T17:55:29","modified_gmt":"2025-06-04T10:09:28","slug":"python-%e5%90%84%e7%a8%ae%e5%9d%87%e7%b7%9a-10ma-20ma%e5%9d%87%e7%b7%9a","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/python-%e5%90%84%e7%a8%ae%e5%9d%87%e7%b7%9a-10ma-20ma%e5%9d%87%e7%b7%9a\/","title":{"rendered":"Python \u5404\u7a2e\u5747\u7dda (10MA\/20MA) \u6559\u5b78 | \u5982\u4f55\u5b89\u88dd\u8207\u4f7f\u7528 pandas"},"content":{"rendered":"<h3>\u5b89\u88dd pandas<\/h3>\n<p>pandas \u662f\u4e00\u500b\u5f37\u5927\u7684 Python \u6578\u64da\u5206\u6790\u5eab\uff0c\u63d0\u4f9b\u5feb\u901f\u3001\u9748\u6d3b\u4e14\u53ef\u8868\u9054\u7684\u6578\u64da\u7d50\u69cb\uff0c\u4f7f\u6578\u64da\u8655\u7406\u8b8a\u5f97\u66f4\u52a0\u7c21\u55ae\u76f4\u89c0\u3002\u5b83\u662f\u9032\u884c\u5be6\u7528\u3001\u771f\u5be6\u4e16\u754c\u6578\u64da\u5206\u6790\u7684\u57fa\u790e\u5de5\u5177\uff0c\u65e8\u5728\u6210\u70ba\u6240\u6709\u8a9e\u8a00\u4e2d\u6700\u5f37\u5927\u3001\u6700\u9748\u6d3b\u7684\u958b\u6e90\u6578\u64da\u5206\u6790\/\u64cd\u4f5c\u5de5\u5177\u4e4b\u4e00\u3002\u4f7f\u7528 pandas\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u5206\u6790\u80a1\u7968\u3001\u865b\u64ec\u8ca8\u5e63\uff0c\u4e26\u4e14\u5167\u5efa\u8a31\u591a\u6307\u6a19\u516c\u5f0f\u3002<\/p>\n<p>\u5b98\u7db2: [pandas GitHub](https:\/\/github.com\/pandas-dev\/pandas)<\/p>\n<h3>\u5b89\u88dd pandas<\/h3>\n<p>\u82e5\u8981\u5b89\u88dd pandas\uff0c\u8acb\u78ba\u4fdd\u4f60\u5df2\u7d93\u5b89\u88dd\u4e86 Python\u3002\u63a5\u8457\u5728\u7d42\u7aef\u6a5f\u57f7\u884c\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<p>&#8220;`bash<br \/>\npip install pandas<br \/>\n&#8220;`<\/p>\n<h3>\u5747\u7dda (MA) \u7c21\u6613\u4f7f\u7528<\/h3>\n<p>\u5747\u7dda\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u6280\u8853\u5206\u6790\u5de5\u5177\uff0c\u7528\u4f86\u5e73\u6ed1\u50f9\u683c\u6578\u64da\u4e26\u8b58\u5225\u8da8\u52e2\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8a08\u7b97 5 \u65e5\u5747\u7dda\u548c 10 \u65e5\u5747\u7dda\u7684\u793a\u7bc4\uff1a<\/p>\n<h4>5MA<\/h4>\n<p>&#8220;`python<br \/>\nimport pandas as pd<\/p>\n<p>ma = 5<br \/>\nyourDataList = [1, 2, 3, 5, 6, 10, 12, 14, 12, 30]\nmyObj = pd.Series(yourDataList).rolling(ma).mean()<br \/>\nprint(myObj)<br \/>\n&#8220;`<\/p>\n<p>\u5728\u9019\u6bb5\u7a0b\u5f0f\u78bc\u4e2d\uff0c`rolling(ma)` \u8868\u793a\u6211\u5011\u8981\u8a08\u7b97\u7684\u7a97\u53e3\u5927\u5c0f\u70ba 5\u3002\u63a5\u8457\uff0c`mean()` \u51fd\u6578\u5c07\u8a08\u7b97\u9019\u500b\u7a97\u53e3\u5167\u7684\u5e73\u5747\u503c\u3002<\/p>\n<h4>\u5747\u7dda\u8a08\u7b97\u793a\u7bc4<\/h4>\n<p>\u8b93\u6211\u5011\u4f86\u770b\u770b\u5982\u4f55\u89e3\u91cb\u9019\u4e9b\u6578\u64da\u3002<br \/>\n&#8211; \u5c0d\u65bc\u5217\u8868\u4e2d\u7684\u524d 5 \u500b\u6578\u5b57\uff0c\u8a08\u7b97\u5176\u5e73\u5747\u503c\u6642\uff0c\u516c\u5f0f\u70ba\uff1a(1 + 2 + 3 + 5 + 6) \/ 5 = 3.4\u3002<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/08\/wp_editor_md_b1ac522c1d7ba0dc595b4a1879759f87.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/08\/wp_editor_md_b1ac522c1d7ba0dc595b4a1879759f87.jpg\" alt=\"\u5747\u7dda\u793a\u7bc4\u5716\" title=\"\"><\/a><\/p>\n<h3>\u53c3\u6578\u8a73\u89e3<\/h3>\n<p>\u4ee5\u4e0b\u662f `rolling` \u51fd\u6578\u7684\u53c3\u6578\u8a73\u89e3\uff1a<\/p>\n<p>&#8220;`python<br \/>\nDataFrame.rolling(window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None)<br \/>\n&#8220;`<\/p>\n<p>&#8211; `<code>window<\/code>`\uff1a\u8a08\u7b97\u5747\u7dda\u7684\u6642\u9593\u7a97\u5927\u5c0f\uff0c\u53ef\u4ee5\u7528\u6574\u6578\u6216\u6642\u9593\u504f\u79fb\u3002<br \/>\n&#8211; `<code>min_periods<\/code>`\uff1a\u6bcf\u500b\u7a97\u53e3\u6700\u5c11\u9700\u8981\u7684\u89c0\u6e2c\u503c\u6578\u91cf\uff0c\u9ed8\u8a8d\u70ba None\u3002<br \/>\n&#8211; `<code>center<\/code>`\uff1a\u5982\u679c\u8a2d\u7f6e\u70ba True\uff0c\u7a97\u53e3\u7684\u6a19\u7c64\u5c07\u6703\u5c45\u4e2d\uff0c\u9ed8\u8a8d\u70ba False\u3002<br \/>\n&#8211; `<code>win_type<\/code>`\uff1a\u7a97\u53e3\u7684\u985e\u578b\uff0c\u53ef\u9078\u7684\u5b57\u7b26\u4e32\u985e\u578b\uff0c\u9ed8\u8a8d\u70ba None\u3002<br \/>\n&#8211; `<code>on<\/code>`\uff1a\u6307\u5b9a\u8981\u8a08\u7b97\u7684\u5217\u540d\uff0c\u5c0d\u65bc DataFrame \u5fc5\u586b\u3002<br \/>\n&#8211; `<code>axis<\/code>`\uff1a\u9ed8\u8a8d\u70ba 0\uff0c\u5373\u5c0d\u5217\u9032\u884c\u8a08\u7b97\u3002<br \/>\n&#8211; `<code>closed<\/code>`\uff1a\u5b9a\u7fa9\u5340\u9593\u7684\u958b\u9589\uff0c\u652f\u6301 int \u985e\u578b\u7684 window\u3002<\/p>\n<h3>\u5ef6\u4f38\u61c9\u7528<\/h3>\n<p>\u9664\u4e86\u5747\u7dda\uff0cpandas \u9084\u53ef\u4ee5\u7528\u65bc\u5176\u4ed6\u8a31\u591a\u6578\u64da\u5206\u6790\u4efb\u52d9\uff0c\u4f8b\u5982\uff1a<br \/>\n&#8211; \u6578\u64da\u6e05\u7406\u8207\u9810\u8655\u7406<br \/>\n&#8211; \u6578\u64da\u8996\u89ba\u5316\uff08\u914d\u5408 Matplotlib \u6216 Seaborn\uff09<br \/>\n&#8211; \u9ad8\u7d1a\u6578\u64da\u64cd\u4f5c\uff08\u5982\u5408\u4f75\u3001\u5206\u7d44\u3001\u900f\u8996\u8868\u7b49\uff09<\/p>\n<p>\u60f3\u4e86\u89e3\u66f4\u591a\u95dc\u65bc Python \u7684\u6587\u7ae0\uff0c\u8acb\u53c3\u8003\u9019\u88e1\uff1a[Python \u6aa2\u67e5 dict \u662f\u5426\u6709\u9019\u500b key](https:\/\/badgameshow.com\/steven\/python\/python-\u7b46\u8a18)\u3002<\/p>\n<hr \/>\n<h3>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h3>\n<p>**Q1: \u5982\u4f55\u8a08\u7b97\u4e0d\u540c\u6642\u9593\u7a97\u53e3\u7684\u5747\u7dda\uff1f**<br \/>\nA1: \u4fee\u6539 `rolling` \u51fd\u6578\u4e2d\u7684 `window` \u53c3\u6578\u5373\u53ef\u8a08\u7b97\u4e0d\u540c\u6642\u9593\u7a97\u53e3\u7684\u5747\u7dda\uff0c\u4f8b\u5982 `window=10` \u8a08\u7b97 10 \u65e5\u5747\u7dda\u3002<\/p>\n<p>**Q2: pandas \u662f\u5426\u652f\u6301\u7f3a\u5931\u503c\u8655\u7406\uff1f**<br \/>\nA2: \u662f\u7684\uff0cpandas \u63d0\u4f9b\u4e86\u8a31\u591a\u65b9\u6cd5\u4f86\u8655\u7406\u7f3a\u5931\u503c\uff0c\u4f8b\u5982\u4f7f\u7528 `fillna()` \u51fd\u6578\u586b\u5145\u7f3a\u5931\u503c\u3002<\/p>\n<p>**Q3: \u662f\u5426\u53ef\u4ee5\u5c07\u5747\u7dda\u7d50\u679c\u53ef\u8996\u5316\uff1f**<br \/>\nA3: \u53ef\u4ee5\u4f7f\u7528 Matplotlib \u6216 Seaborn \u7b49\u5eab\u9032\u884c\u53ef\u8996\u5316\uff0c\u9019\u6a23\u53ef\u4ee5\u66f4\u76f4\u89c0\u5730\u89c0\u5bdf\u8da8\u52e2\u8b8a\u5316\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pandas\u662f\u4e00\u500bPython SDK\uff0c\u63d0\u4f9b\u5feb\u901f\uff0c\u9748\u6d3b\u548c\u53ef\u8868\u9054\u7684\u6578\u64da\u7d50\u69cb\uff0c\u4f7f\u6578\u64da\u65e2\u7c21\u55ae\u53c8\u76f4\u89c0\u3002\u5b83\u65e8\u5728\u6210\u70ba\u5728Python\u4e2d\u9032\u884c\u5be6\u7528\uff0c\u771f\u5be6\u4e16\u754c\u6578\u64da\u5206\u6790\u7684\u57fa\u672c\u9ad8\u7d1a\u69cb\u5efa\u584a\u3002\u6b64\u5916\uff0c\u5176\u66f4\u5ee3\u6cdb\u7684\u76ee\u6a19\u662f\u6210\u70ba\u4efb\u4f55\u8a9e\u8a00\u4e2d\u53ef\u7528\u7684\u6700\u5f37\u5927\uff0c\u6700\u9748\u6d3b\u7684\u958b\u6e90\u6578\u64da\u5206\u6790\/\u64cd\u4f5c\u5de5\u5177\u3002\u5b83\u5df2\u7d93\u671d\u8457\u9019\u500b\u76ee\u6a19\u9081\u9032\u4e86<\/p>\n<p>\u53cd\u6b63\u5c31\u662f\u4e00\u500b\u53ef\u4ee5\u5206\u6790\u80a1\u7968\/\u865b\u64ec\u8ca8\u5e63 \u88e1\u9762\u585e\u4e00\u5806\u6307\u6a19\u516c\u5f0f\u7684SDK \u8b9a\u8b9a<\/p>\n","protected":false},"author":1,"featured_media":559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[37,36,38,39],"class_list":["post-187","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-ma","tag-pandas","tag-38","tag-39"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/11\/cup-1-1.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-31","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":8,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":13078,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/187\/revisions\/13078"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/559"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}