{"id":4071,"date":"2025-10-17T17:44:44","date_gmt":"2025-10-17T09:44:44","guid":{"rendered":"http:\/\/viplao.com\/?p=4071"},"modified":"2025-10-18T11:37:50","modified_gmt":"2025-10-18T03:37:50","slug":"%e3%80%90%e8%bf%90%e8%90%a5%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-%e5%9f%ba%e7%a1%80%e7%af%87%e3%80%91-%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2025\/10\/17\/%e3%80%90%e8%bf%90%e8%90%a5%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-%e5%9f%ba%e7%a1%80%e7%af%87%e3%80%91-%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96%e5%85%a5%e9%97%a8\/","title":{"rendered":"\u3010\u8fd0\u8425\u6570\u636e\u5206\u6790-\u57fa\u7840\u7bc7\u3011 \u6570\u636e\u53ef\u89c6\u5316\u5165\u95e8"},"content":{"rendered":"\n<p><strong>\u3010\u7406\u8bba\u8bb2\u89e3\u3011<\/strong><\/p>\n\n\n\n<p>\u6570\u636e\u5206\u6790\u4e0d\u4ec5\u4ec5\u662f\u6570\u5b57\uff0c\u66f4\u9700\u8981\u201c\u770b\u5f97\u89c1\u201d\u7684\u6d1e\u5bdf\u3002\u6570\u636e\u53ef\u89c6\u5316\u5c31\u662f\u5c06\u6570\u636e\u8f6c\u6362\u6210\u56fe\u8868\uff0c\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u7406\u89e3\u6570\u636e\u6a21\u5f0f\u3001\u8d8b\u52bf\u548c\u5f02\u5e38\u3002<\/p>\n\n\n\n<ul>\n<li><strong>Matplotlib\uff1a<\/strong>&nbsp;Python\u6700\u57fa\u7840\u3001\u6700\u7075\u6d3b\u7684\u7ed8\u56fe\u5e93\u3002\u4f60\u53ef\u4ee5\u7528\u5b83\u753b\u51fa\u5404\u79cd\u9759\u6001\u56fe\u8868\uff0c\u5e76\u5bf9\u56fe\u8868\u7684\u6bcf\u4e00\u4e2a\u7ec6\u8282\u8fdb\u884c\u7cbe\u7ec6\u63a7\u5236\u3002<\/li>\n\n\n\n<li><strong>Seaborn\uff1a<\/strong>&nbsp;\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u7f8e\u89c2\u7684\u56fe\u8868\u6837\u5f0f\u548c\u66f4\u4e30\u5bcc\u7684\u7edf\u8ba1\u56fe\u8868\u7c7b\u578b\uff0c\u8ba9\u4f60\u7528\u66f4\u5c11\u7684\u4ee3\u7801\u753b\u51fa\u66f4\u6f02\u4eae\u7684\u56fe\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u3010\u4ee3\u7801\u5b9e\u4f8b\u4e0e\u7535\u5546\u573a\u666f\u6848\u4f8b\u3011<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u524d\u9762\u5904\u7406\u597d\u7684\u7535\u5546\u8ba2\u5355\u6570\u636e&nbsp;<code>df_orders<\/code>&nbsp;\u6765\u8fdb\u884c\u53ef\u89c6\u5316\u3002<\/p>\n\n\n\n<p>python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# \u8bbe\u7f6e\u4e2d\u6587\u663e\u793a\u548c\u8d1f\u53f7\u6b63\u5e38\u663e\u793a\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei'] # \u6307\u5b9a\u9ed8\u8ba4\u5b57\u4f53\u4e3a\u9ed1\u4f53\nplt.rcParams&#91;'axes.unicode_minus'] = False # \u89e3\u51b3\u4fdd\u5b58\u56fe\u50cf\u662f\u8d1f\u53f7'-'\u663e\u793a\u4e3a\u65b9\u5757\u7684\u95ee\u9898\n\n# \u52a0\u8f7d\u7535\u5546\u8ba2\u5355\u6570\u636e (\u5047\u8bbe\u5df2\u5305\u542b total_amount \u548c order_date)\ndf_orders = pd.read_csv('ecommerce_orders.csv')\ndf_orders&#91;'order_date'] = pd.to_datetime(df_orders&#91;'order_date'])\ndf_orders&#91;'total_amount'] = df_orders&#91;'price'] * df_orders&#91;'quantity']\n\nprint(\"\u7528\u4e8e\u53ef\u89c6\u5316\u7684\u8ba2\u5355\u6570\u636e\u9884\u89c8:\\n\", df_orders.head())\n\n# --- 3.1 Matplotlib\u57fa\u7840 ---\nprint(\"\\n--- Matplotlib\u57fa\u7840\u7ed8\u56fe ---\")\n\n# \u7535\u5546\u573a\u666f\uff1a\u6bcf\u65e5\u9500\u552e\u989d\u6298\u7ebf\u56fe (\u8d8b\u52bf\u5206\u6790)\ndaily_sales = df_orders.groupby('order_date')&#91;'total_amount'].sum()\nplt.figure(figsize=(10, 6)) # \u8bbe\u7f6e\u56fe\u8868\u5927\u5c0f\nplt.plot(daily_sales.index, daily_sales.values, marker='o', linestyle='-', color='skyblue') # \u7ed8\u5236\u6298\u7ebf\u56fe\nplt.title('\u6bcf\u65e5\u9500\u552e\u989d\u8d8b\u52bf') # \u8bbe\u7f6e\u6807\u9898\nplt.xlabel('\u65e5\u671f') # \u8bbe\u7f6eX\u8f74\u6807\u7b7e\nplt.ylabel('\u9500\u552e\u989d (\u5143)') # \u8bbe\u7f6eY\u8f74\u6807\u7b7e\nplt.grid(True) # \u663e\u793a\u7f51\u683c\nplt.xticks(rotation=45) # X\u8f74\u6807\u7b7e\u65cb\u8f6c45\u5ea6\nplt.tight_layout() # \u8c03\u6574\u5e03\u5c40\uff0c\u907f\u514d\u6807\u7b7e\u91cd\u53e0\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u5546\u54c1\u7c7b\u522b\u9500\u552e\u989d\u67f1\u72b6\u56fe (\u54c1\u7c7b\u8d21\u732e\u5206\u6790)\ncategory_sales = df_orders.groupby('category')&#91;'total_amount'].sum().sort_values(ascending=False)\nplt.figure(figsize=(10, 6))\nplt.bar(category_sales.index, category_sales.values, color='lightcoral') # \u7ed8\u5236\u67f1\u72b6\u56fe\nplt.title('\u5404\u5546\u54c1\u7c7b\u522b\u603b\u9500\u552e\u989d')\nplt.xlabel('\u5546\u54c1\u7c7b\u522b')\nplt.ylabel('\u9500\u552e\u989d (\u5143)')\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u652f\u4ed8\u65b9\u5f0f\u5360\u6bd4\u997c\u56fe (\u652f\u4ed8\u504f\u597d\u5206\u6790)\npayment_counts = df_orders&#91;'payment_method'].value_counts()\nplt.figure(figsize=(8, 8))\nplt.pie(payment_counts, labels=payment_counts.index, autopct='%1.1f%%', startangle=90, colors=sns.color_palette('pastel'))\nplt.title('\u652f\u4ed8\u65b9\u5f0f\u5360\u6bd4')\nplt.axis('equal') # \u4f7f\u997c\u56fe\u4e3a\u5706\u5f62\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u6563\u70b9\u56fe (\u63a2\u7d22\u4ef7\u683c\u4e0e\u6570\u91cf\u5173\u7cfb)\nplt.figure(figsize=(10, 6))\nplt.scatter(df_orders&#91;'price'], df_orders&#91;'quantity'], alpha=0.7, color='green')\nplt.title('\u5546\u54c1\u4ef7\u683c\u4e0e\u8d2d\u4e70\u6570\u91cf\u6563\u70b9\u56fe')\nplt.xlabel('\u5546\u54c1\u5355\u4ef7 (\u5143)')\nplt.ylabel('\u8d2d\u4e70\u6570\u91cf')\nplt.grid(True, linestyle='--', alpha=0.6)\nplt.show()\n\n\n# --- 3.2 Seaborn\u7f8e\u5316\u56fe\u8868 ---\nprint(\"\\n--- Seaborn\u7f8e\u5316\u4e0e\u9ad8\u7ea7\u56fe\u8868 ---\")\n\n# \u8bbe\u7f6eSeaborn\u98ce\u683c\nsns.set_style(\"whitegrid\") # \u8bbe\u7f6e\u80cc\u666f\u7f51\u683c\nsns.set_palette(\"muted\") # \u8bbe\u7f6e\u989c\u8272\u677f\n\n# \u7535\u5546\u573a\u666f\uff1a\u6bcf\u65e5\u9500\u552e\u989d\u6298\u7ebf\u56fe (Seaborn\u7248\uff0c\u66f4\u7f8e\u89c2)\nplt.figure(figsize=(10, 6))\nsns.lineplot(x=daily_sales.index, y=daily_sales.values, marker='o')\nplt.title('\u6bcf\u65e5\u9500\u552e\u989d\u8d8b\u52bf (Seaborn)')\nplt.xlabel('\u65e5\u671f')\nplt.ylabel('\u9500\u552e\u989d (\u5143)')\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u5546\u54c1\u7c7b\u522b\u9500\u552e\u989d\u67f1\u72b6\u56fe (Seaborn\u7248\uff0c\u66f4\u7f8e\u89c2)\nplt.figure(figsize=(10, 6))\nsns.barplot(x=category_sales.index, y=category_sales.values)\nplt.title('\u5404\u5546\u54c1\u7c7b\u522b\u603b\u9500\u552e\u989d (Seaborn)')\nplt.xlabel('\u5546\u54c1\u7c7b\u522b')\nplt.ylabel('\u9500\u552e\u989d (\u5143)')\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u4e0d\u540c\u57ce\u5e02\u9500\u552e\u989d\u5bf9\u6bd4 (\u7bb1\u7ebf\u56fe - \u63a2\u7d22\u5206\u5e03\u548c\u5f02\u5e38)\nplt.figure(figsize=(12, 7))\nsns.boxplot(x='shipping_city', y='total_amount', data=df_orders)\nplt.title('\u5404\u57ce\u5e02\u8ba2\u5355\u603b\u91d1\u989d\u5206\u5e03 (\u7bb1\u7ebf\u56fe)')\nplt.xlabel('\u6536\u8d27\u57ce\u5e02')\nplt.ylabel('\u8ba2\u5355\u603b\u91d1\u989d (\u5143)')\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()\n\n# \u7535\u5546\u573a\u666f\uff1a\u4ef7\u683c\u548c\u6570\u91cf\u7684\u70ed\u529b\u56fe (\u63a2\u7d22\u9ad8\u5bc6\u5ea6\u533a\u57df)\n# \u5148\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u805a\u5408\uff0c\u4ee5\u4fbf\u7ed8\u5236\u70ed\u529b\u56fe\nprice_qty_pivot = df_orders.pivot_table(index='price', columns='quantity', values='order_id', aggfunc='count').fillna(0)\nplt.figure(figsize=(10, 8))\nsns.heatmap(price_qty_pivot, cmap='viridis', annot=True, fmt=\".0f\", linewidths=.5)\nplt.title('\u5546\u54c1\u4ef7\u683c\u4e0e\u8d2d\u4e70\u6570\u91cf\u70ed\u529b\u56fe')\nplt.xlabel('\u8d2d\u4e70\u6570\u91cf')\nplt.ylabel('\u5546\u54c1\u5355\u4ef7')\nplt.tight_layout()\nplt.show()<\/code><\/pre>\n\n\n\n<p><strong>\u3010\u4e92\u52a8\u95ee\u7b54\u3011<\/strong><\/p>\n\n\n\n<ul>\n<li>Matplotlib\u548cSeaborn\u5728\u529f\u80fd\u548c\u4f7f\u7528\u4e0a\u6709\u54ea\u4e9b\u5f02\u540c\u70b9\uff1f<\/li>\n\n\n\n<li>\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u3001\u6563\u70b9\u56fe\u5404\u81ea\u9002\u7528\u4e8e\u4ec0\u4e48\u7c7b\u578b\u7684\u7535\u5546\u6570\u636e\u5206\u6790\u573a\u666f\uff1f<\/li>\n\n\n\n<li>\u7bb1\u7ebf\u56fe\u80fd\u63d0\u4f9b\u54ea\u4e9b\u5173\u4e8e\u6570\u636e\u5206\u5e03\u7684\u4fe1\u606f\uff1f\u5728\u7535\u5546\u6570\u636e\u4e2d\uff0c\u5b83\u80fd\u5e2e\u52a9\u6211\u4eec\u53d1\u73b0\u4ec0\u4e48\uff1f<\/li>\n\n\n\n<li>\u5982\u4f55\u8c03\u6574\u56fe\u8868\u7684\u6807\u9898\u3001\u8f74\u6807\u7b7e\u3001\u5b57\u4f53\u5927\u5c0f\u548c\u989c\u8272\uff1f<\/li>\n\n\n\n<li>\u5982\u679c\u56fe\u8868\u4e2d\u7684\u4e2d\u6587\u663e\u793a\u4e71\u7801\uff0c\u5e94\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\uff08\u63d0\u793a\uff1a<code>plt.rcParams<\/code>\uff09<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u7406\u8bba\u8bb2\u89e3\u3011 \u6570\u636e\u5206\u6790\u4e0d\u4ec5\u4ec5\u662f\u6570\u5b57\uff0c\u66f4\u9700\u8981\u201c\u770b\u5f97\u89c1\u201d\u7684\u6d1e\u5bdf\u3002\u6570\u636e\u53ef\u89c6\u5316\u5c31\u662f\u5c06\u6570\u636e\u8f6c\u6362\u6210\u56fe\u8868\uff0c\u5e2e\u52a9\u6211\u4eec&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2025\/10\/17\/%e3%80%90%e8%bf%90%e8%90%a5%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-%e5%9f%ba%e7%a1%80%e7%af%87%e3%80%91-%e6%95%b0%e6%8d%ae%e5%8f%af%e8%a7%86%e5%8c%96%e5%85%a5%e9%97%a8\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u3010\u8fd0\u8425\u6570\u636e\u5206\u6790-\u57fa\u7840\u7bc7\u3011 \u6570\u636e\u53ef\u89c6\u5316\u5165\u95e8<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[28],"views":492,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4071"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=4071"}],"version-history":[{"count":2,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4071\/revisions"}],"predecessor-version":[{"id":4089,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4071\/revisions\/4089"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=4071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=4071"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=4071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}