{"id":323085,"date":"2024-01-07T08:41:19","date_gmt":"2024-01-07T00:41:19","guid":{"rendered":"https:\/\/www.idc.net\/help\/323085\/"},"modified":"2024-01-07T08:41:19","modified_gmt":"2024-01-07T00:41:19","slug":"%e5%ae%9e%e7%94%a8%ef%bc%81python%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%b8%8e%e8%81%9a%e5%90%88%e5%88%86%e6%9e%90%ef%bc%9a%e6%8e%8c%e6%8f%a1%e6%95%b0%e6%8d%ae%e6%a6%82%e8%a7%88","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/323085\/","title":{"rendered":"\u5b9e\u7528\uff01Python\u6570\u636e\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\uff1a\u638c\u63e1\u6570\u636e\u6982\u89c8"},"content":{"rendered":"<p style=\"text-align: justify\"><span>Python\u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728\u6570\u636e\u5206\u6790\u548c\u6570\u636e\u5904\u7406\u65b9\u9762\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u5728\u6570\u636e\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\u4e2d\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5bf9\u6570\u636e\u8fdb\u884c\u6982\u89c8\u3001\u5206\u7ec4\u548c\u805a\u5408\u5206\u6790\uff0c\u5e76\u4ece\u4e2d\u83b7\u53d6\u6709\u7528\u7684\u4fe1\u606f\u3002<\/span><\/p>\n<p style=\"text-align: justify\"><span>\u4e0b\u9762\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u6570\u636e\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\uff0c\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/span><\/p>\n<h4><span>1\u3001\u6570\u636e\u6982\u89c8<\/span><\/h4>\n<p style=\"text-align: justify\"><span>1\uff09\u3001\u5bfc\u5165\u6240\u9700\u5e93<\/span><\/p>\n<p style=\"text-align: justify\"><span>2\uff09\u3001\u52a0\u8f7d\u6570\u636e\u96c6<\/span><\/p>\n<p style=\"text-align: justify\"><span>3\uff09\u3001\u67e5\u770b\u6570\u636e\u96c6\u7684\u57fa\u672c\u4fe1\u606f<\/span><\/p>\n<p style=\"text-align: justify\"><span>4\uff09\u3001\u6570\u636e\u6e05\u6d17\u4e0e\u9884\u5904\u7406<\/span><\/p>\n<h4><span>2\u3001\u6570\u636e\u5206\u7ec4<\/span><\/h4>\n<p style=\"text-align: justify\"><span>1\uff09\u3001\u6839\u636e\u6307\u5b9a\u5217\u8fdb\u884c\u5206\u7ec4<\/span><\/p>\n<p style=\"text-align: justify\"><span>2\uff09\u3001\u5206\u7ec4\u540e\u7684\u6570\u636e\u53ef\u89c6\u5316<\/span><\/p>\n<h4><span>3\u3001\u805a\u5408\u5206\u6790<\/span><\/h4>\n<p style=\"text-align: justify\"><span>1\uff09\u3001\u8ba1\u7b97\u5206\u7ec4\u540e\u7684\u5404\u4e2a\u7edf\u8ba1\u91cf<\/span><\/p>\n<p style=\"text-align: justify\"><span>2\uff09\u3001\u6570\u636e\u900f\u89c6\u8868\u7684\u751f\u6210\u4e0e\u5206\u6790<\/span><\/p>\n<p style=\"text-align: justify\"><span>4\u3001\u7ed3\u679c\u5c55\u793a\u4e0e\u89e3\u8bfb<\/span><\/p>\n<p style=\"text-align: justify\"><span>\u4e0b\u9762\u8ba9\u6211\u4eec\u4e00\u6b65\u6b65\u5730\u8fdb\u884c\u5177\u4f53\u7684\u5b9e\u73b0\u3002<\/span><\/p>\n<h4>1. \u6570\u636e\u6982\u89c8<\/h4>\n<p style=\"text-align: justify\"><span>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u6240\u9700\u7684\u5e93\uff0c\u4f8b\u5982pandas\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\uff0cmatplotlib\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7b49\u3002<\/span><\/p>\n<pre><code>import pandas as pd\nimport matplotlib.pyplot as plt<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u52a0\u8f7d\u6570\u636e\u96c6\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3adata.csv\u7684CSV\u6587\u4ef6\uff0c\u5305\u542b\u4e86\u9700\u8981\u8fdb\u884c\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\u7684\u6570\u636e\u3002<\/span><\/p>\n<pre><code>data = pd.read_csv('data.csv')<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u67e5\u770b\u6570\u636e\u96c6\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u4f8b\u5982\u524d\u51e0\u884c\u6570\u636e\u3001\u6570\u636e\u7684\u5217\u540d\u3001\u6570\u636e\u7684\u7ef4\u5ea6\u7b49\u3002<\/span><\/p>\n<pre><code>data.head()\ndata.columns\ndata.shape<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u5728\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u4e0e\u805a\u5408\u524d\uff0c\u6211\u4eec\u53ef\u80fd\u8fd8\u9700\u8981\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u4e0e\u9884\u5904\u7406\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u53bb\u9664\u7a7a\u503c\u3001\u5904\u7406\u5f02\u5e38\u503c\u7b49\u3002<\/span><\/p>\n<p style=\"text-align:center\">\n<h4>2. \u6570\u636e\u5206\u7ec4<\/h4>\n<p style=\"text-align: justify\"><span>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u6307\u5b9a\u7684\u5217\u8fdb\u884c\u6570\u636e\u5206\u7ec4\u3002\u5047\u8bbe\u6211\u4eec\u5e0c\u671b\u6839\u636ecategory\u5217\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u3002<\/span><\/p>\n<pre><code>grouped_data = data.groupby('category')<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u5206\u7ec4\u540e\u7684\u6570\u636e\uff0c\u5c06\u6bcf\u4e2a\u5206\u7ec4\u7684\u6570\u636e\u53ef\u89c6\u5316\u5c55\u793a\u51fa\u6765\u3002<\/span><\/p>\n<pre><code>for name, group in grouped_data:\n    plt.plot(group['date'], group['value'], label=name)\n    \nplt.legend()\nplt.xlabel('Date')\nplt.ylabel('Value')\nplt.title('Grouped Data Visualization')\nplt.show()<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a\u5206\u7ec4\u7684\u6570\u636e\u5728\u65f6\u95f4\u4e0a\u7684\u53d8\u5316\u60c5\u51b5\u3002<\/span><\/p>\n<h4>3. \u805a\u5408\u5206\u6790<\/h4>\n<p style=\"text-align: justify\"><span>\u5728\u8fdb\u884c\u805a\u5408\u5206\u6790\u4e4b\u524d\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97\u5206\u7ec4\u540e\u7684\u5404\u4e2a\u7edf\u8ba1\u91cf\uff0c\u4f8b\u5982\u5e73\u5747\u503c\u3001\u603b\u548c\u3001\u6700\u5927\u503c\u3001\u6700\u5c0f\u503c\u7b49\u3002<\/span><\/p>\n<pre><code>grouped_data.mean()\ngrouped_data.sum()\ngrouped_data.max()\ngrouped_data.min()<\/code><\/pre>\n<p style=\"text-align: justify\"><span>\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6570\u636e\u900f\u89c6\u8868\u6765\u66f4\u52a0\u65b9\u4fbf\u5730\u5c55\u793a\u548c\u5206\u6790\u5206\u7ec4\u805a\u5408\u540e\u7684\u7ed3\u679c\u3002<\/span><\/p>\n<pre><code>pivot_table = pd.pivot_table(data, values='value', index='category', columns='date', aggfunc='mean')<\/code><\/pre>\n<h4>4. \u7ed3\u679c\u5c55\u793a\u4e0e\u89e3\u8bfb<\/h4>\n<p style=\"text-align: justify\"><span>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\u7684\u7ed3\u679c\u8fdb\u884c\u5c55\u793a\u548c\u89e3\u8bfb\u3002\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u4f7f\u7528\u5408\u9002\u7684\u56fe\u8868\u548c\u65b9\u6cd5\uff0c\u4f8b\u5982\u67f1\u72b6\u56fe\u3001\u6298\u7ebf\u56fe\u3001\u997c\u56fe\u7b49\uff0c\u6765\u5448\u73b0\u6570\u636e\u7684\u7279\u5f81\u548c\u8d8b\u52bf\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728\u6570\u636e\u5206\u6790\u548c\u6570\u636e\u5904\u7406\u65b9\u9762\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u5728\u6570\u636e\u5206\u7ec4\u4e0e\u805a\u5408\u5206\u6790\u4e2d\uff0cPyth [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":323086,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-323085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/323085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=323085"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/323085\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/323086"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=323085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=323085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=323085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}