{"id":623,"date":"2025-12-13T06:55:08","date_gmt":"2025-12-12T22:55:08","guid":{"rendered":"https:\/\/www.idcyz.com\/blog\/?p=623"},"modified":"2025-12-13T06:55:08","modified_gmt":"2025-12-12T22:55:08","slug":"%e5%9f%ba%e4%ba%8epython%e7%9a%84%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e6%a1%88%e4%be%8b%ef%bc%9a%e6%8f%90%e5%8d%87%e6%95%b0%e6%8d%ae%e5%a4%84%e7%90%86%e6%95%88%e7%8e%87%e7%9a%84%e5%ae%9e%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.idcyz.com\/blog\/623.html","title":{"rendered":"\u57fa\u4e8ePython\u7684\u6570\u636e\u5206\u6790\u6848\u4f8b\uff1a\u63d0\u5347\u6570\u636e\u5904\u7406\u6548\u7387\u7684\u5b9e\u7528\u6280\u5de7"},"content":{"rendered":"<p><p>\u5728\u5f53\u4eca\u6570\u636e\u9a71\u52a8\u7684\u65f6\u4ee3\uff0c\u6570\u636e\u5206\u6790\u5df2\u6210\u4e3a\u4f01\u4e1a\u548c\u4e2a\u4eba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u5b9e\u4f8b\uff0c\u4f7f\u7528<strong>Python<\/strong>\u5de5\u5177\u8fdb\u884c\u6570\u636e\u5206\u6790\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u67d0\u4e00\u4e1a\u52a1\u95ee\u9898\u7684\u6df1\u5165\u63a2\u7d22\u3002\u6211\u4eec\u5c06\u4ee5\u5206\u6790\u67d0\u7535\u5546\u7f51\u7ad9\u7684\u9500\u91cf\u6570\u636e\u4e3a\u4f8b\uff0c\u4efb\u52a1\u662f\u627e\u51fa\u4e0d\u540c\u4ea7\u54c1\u7c7b\u522b\u7684\u9500\u91cf\u8d8b\u52bf\u548c\u7528\u6237\u8d2d\u4e70\u884c\u4e3a\uff0c\u4ee5\u4fbf\u4e3a\u4e1a\u52a1\u51b3\u7b56\u63d0\u4f9b\u53c2\u8003\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.idcyz.com\/blog\/wp-content\/uploads\/2025\/07\/6nUYwC7n.jpg\" alt=\"\u57fa\u4e8ePython\u7684\u6570\u636e\u5206\u6790\u6848\u4f8b\uff1a\u63d0\u5347\u6570\u636e\u5904\u7406\u6548\u7387\u7684\u5b9e\u7528\u6280\u5de7\" title=\"\u57fa\u4e8ePython\u7684\u6570\u636e\u5206\u6790\u6848\u4f8b\uff1a\u63d0\u5347\u6570\u636e\u5904\u7406\u6548\u7387\u7684\u5b9e\u7528\u6280\u5de7\"><\/p>\n<\/p>\n<p><h2>1. \u64cd\u4f5c\u524d\u7684\u51c6\u5907\u548c\u80cc\u666f\u4ecb\u7ecd<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u51c6\u5907\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5<strong>Python<\/strong>\u53ca\u76f8\u5173\u5e93\uff1a\u5982<strong>pandas<\/strong>\u3001<strong>numpy<\/strong>\u3001<strong>matplotlib<\/strong>\u548c<strong>seaborn<\/strong>\u3002<\/li>\n<li>\u51c6\u5907\u597d\u9500\u552e\u6570\u636e\u96c6\uff0c\u901a\u5e38\u4e3acsv\u683c\u5f0f\uff0c\u5305\u542b\u4ea7\u54c1ID\u3001\u7c7b\u522b\u3001\u9500\u552e\u989d\u548c\u9500\u552e\u65e5\u671f\u7b49\u5b57\u6bb5\u3002<\/li>\n<li>\u4e86\u89e3\u6570\u636e\u96c6\u7684\u57fa\u672c\u7ed3\u6784\u548c\u5185\u5bb9\uff0c\u4ee5\u4fbf\u4e8e\u5206\u6790\u3002<\/li>\n<\/ul>\n<p><h2>2. \u5b8c\u6210\u4efb\u52a1\u6240\u9700\u7684\u8be6\u7ec6\u3001\u5206\u6b65\u64cd\u4f5c\u6307\u5357<\/h2>\n<\/p>\n<p><h3>\u6b65\u9aa4 1\uff1a\u5b89\u88c5\u6240\u9700\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5\u4e0a\u8ff0\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install pandas numpy matplotlib seaborn<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 2\uff1a\u52a0\u8f7d\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<strong>pandas<\/strong>\u5e93\u52a0\u8f7d\u6570\u636e\u96c6\u5e76\u67e5\u770b\u6570\u636e\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code>import pandas as pd<\/p>\r\n\r\n<p># \u52a0\u8f7d\u6570\u636e\u96c6<\/p>\r\n<p>data = pd.read_csv('sales_data.csv')<\/p>\r\n\r\n<p># \u67e5\u770b\u6570\u636e\u7ed3\u6784<\/p>\r\n<p>print(data.head())<\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4e86\u89e3\u6570\u636e\u7684\u7ed3\u6784\u548c\u5185\u5bb9\uff0c\u4f8b\u5982\u5b57\u6bb5\u540d\u79f0\u548c\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h3>\u6b65\u9aa4 3\uff1a\u6570\u636e\u6e05\u6d17<\/h3>\n<\/p>\n<p><p>\u5728\u5206\u6790\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u6570\u636e\u96c6\u4e2d\u7684\u7f3a\u5931\u503c\u548c\u5f02\u5e38\u503c\u3002<\/p>\n<\/p>\n<p><pre><code># \u67e5\u770b\u7f3a\u5931\u503c<\/p>\r\n<p>print(data.isnull().sum())<\/p>\r\n\r\n<p># \u79fb\u9664\u7f3a\u5931\u503c<\/p>\r\n<p>data.dropna(inplace=True)<\/p>\r\n\r\n<p># \u67e5\u770b\u6570\u636e\u7c7b\u578b\u5e76\u8f6c\u6362\u4e3a\u5408\u9002\u7684\u5f62\u5f0f<\/p>\r\n<p>data['sale_date'] = pd.to_datetime(data['sale_date'])<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 4\uff1a\u6570\u636e\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u5c06\u6839\u636e\u4ea7\u54c1\u7c7b\u522b\u8ba1\u7b97\u6bcf\u4e2a\u6708\u7684\u603b\u9500\u91cf\uff0c\u5e76\u53ef\u89c6\u5316\u8fd9\u4e9b\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code># \u6309\u6708\u4efd\u548c\u7c7b\u522b\u8fdb\u884c\u6c47\u603b<\/p>\r\n<p>monthly_sales = data.resample('M', on='sale_date').sum().reset_index()<\/p>\r\n\r\n<p># \u53ef\u89c6\u5316<\/p>\r\n<p>import matplotlib.pyplot as plt<\/p>\r\n<p>import seaborn as sns<\/p>\r\n\r\n<p>plt.figure(figsize=(12, 6))<\/p>\r\n<p>sns.lineplot(data=monthly_sales, x='sale_date', y='sales_amount', hue='category')<\/p>\r\n<p>plt.title('\u6bcf\u6708\u9500\u91cf\u8d8b\u52bf')<\/p>\r\n<p>plt.xlabel('\u6708\u4efd')<\/p>\r\n<p>plt.ylabel('\u9500\u552e\u989d')<\/p>\r\n<p>plt.legend(title='\u4ea7\u54c1\u7c7b\u522b')<\/p>\r\n<p>plt.show()<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 5\uff1a\u63a2\u7d22\u7528\u6237\u8d2d\u4e70\u884c\u4e3a<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u7528\u6237\u7684\u5e74\u9f84\u3001\u6027\u522b\u7b49\u4fe1\u606f\u6765\u6df1\u5165\u4e86\u89e3\u5176\u8d2d\u4e70\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u5206\u6790\u4e0d\u540c\u6027\u522b\u7528\u6237\u7684\u8d2d\u4e70\u989d\u3002<\/p>\n<\/p>\n<p><pre><code># \u5206\u6790\u6027\u522b\u5bf9\u8d2d\u4e70\u7684\u5f71\u54cd<\/p>\r\n<p>gender_sales = data.groupby('gender')['sales_amount'].sum().reset_index()<\/p>\r\n\r\n<p># \u53ef\u89c6\u5316<\/p>\r\n<p>plt.figure(figsize=(8, 5))<\/p>\r\n<p>sns.barplot(data=gender_sales, x='gender', y='sales_amount')<\/p>\r\n<p>plt.title('\u6027\u522b\u4e0e\u9500\u552e\u989d\u7684\u5173\u7cfb')<\/p>\r\n<p>plt.xlabel('\u6027\u522b')<\/p>\r\n<p>plt.ylabel('\u9500\u552e\u989d')<\/p>\r\n<p>plt.show()<\/code><\/pre>\n<\/p>\n<p><h2>3. \u5173\u952e\u547d\u4ee4\u548c\u4ee3\u7801\u89e3\u6790<\/h2>\n<\/p>\n<ul>\n<li><strong>pd.read_csv()<\/strong>\uff1a\u7528\u4e8e\u4eceCSV\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5e76\u751f\u6210DataFrame\u3002<\/li>\n<li><strong>dropna()<\/strong>\uff1a\u5220\u9664\u7f3a\u5931\u503c\uff0c\u4fdd\u6301\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>resample()<\/strong>\uff1a\u7528\u4e8e\u6309\u65f6\u95f4\u95f4\u9694\u5bf9\u6570\u636e\u8fdb\u884c\u91cd\u91c7\u6837\uff0c\u8fd9\u91cc\u6211\u4eec\u6309\u6708\u8fdb\u884c\u7edf\u8ba1\u3002<\/li>\n<li><strong>sns.lineplot()<\/strong>\u548c<strong>sns.barplot()<\/strong>\uff1a\u7528\u4e8e\u7ed8\u5236\u9500\u552e\u8d8b\u52bf\u548c\u9500\u552e\u989d\u7684\u6761\u5f62\u56fe\uff0c\u4fbf\u4e8e\u6bd4\u8f83\u3002<\/li>\n<\/ul>\n<p><h2>4. \u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u548c\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u636e\u5206\u6790\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u7f3a\u5931\u503c\u5904\u7406\u4e0d\u5f53\uff1a\u5728\u6e05\u6d17\u6570\u636e\u65f6\uff0c\u786e\u4fdd\u4e86\u89e3\u6570\u636e\u7684\u610f\u4e49\uff0c\u907f\u514d\u5927\u9762\u79ef\u5220\u9664\u91cd\u8981\u6570\u636e\u3002<\/li>\n<li>\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\uff1a\u5728\u5904\u7406\u65e5\u671f\u6570\u636e\u65f6\uff0c\u786e\u4fdd\u5c06\u5176\u8f6c\u6362\u4e3a\u6b63\u786e\u7684\u683c\u5f0f\u3002<\/li>\n<li>\u53ef\u89c6\u5316\u95ee\u9898\uff1a\u5982\u679c\u56fe\u5f62\u663e\u793a\u4e0d\u6e05\u6670\uff0c\u8003\u8651\u8c03\u6574\u56fe\u5f62\u7684\u5927\u5c0f\u3001\u7c7b\u578b\u6216\u4e3b\u9898\u3002<\/li>\n<\/ul>\n<p><h2>5. \u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u8fc7\u7a0b\u4e2d\u8fd8\u53ef\u4ee5\u6ce8\u610f\u5230\u4e00\u4e9b\u5b9e\u7528\u6280\u5de7\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u52aa\u529b\u4fdd\u6301\u4ee3\u7801\u7684\u7b80\u6d01\u6027\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u590d\u6742\u6027\u3002<\/li>\n<li>\u5584\u7528\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u56fe\u5f62\u5316\u4fe1\u606f\u5f80\u5f80\u6bd4\u6587\u672c\u6570\u636e\u66f4\u76f4\u89c2\u6613\u61c2\u3002<\/li>\n<li>\u5b9a\u671f\u5907\u4efd\u6570\u636e\uff0c\u907f\u514d\u5728\u5b9e\u9a8c\u4e2d\u9020\u6210\u6570\u636e\u4e22\u5931\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u80fd\u591f\u638c\u63e1\u5982\u4f55\u5229\u7528<strong>Python<\/strong>\u8fdb\u884c\u57fa\u672c\u7684\u6570\u636e\u5206\u6790\u3002\u6570\u636e\u5206\u6790\u5e76\u4e0d\u9700\u8981\u8fc7\u4e8e\u590d\u6742\u7684\u65b9\u5f0f\uff0c\u91cd\u70b9\u5728\u4e8e\u5408\u7406\u5229\u7528\u5de5\u5177\u548c\u7406\u89e3\u6570\u636e\u5185\u5728\u7684\u903b\u8f91\u5173\u7cfb\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u7ed9\u60a8\u5728\u6570\u636e\u5206\u6790\u7684\u65c5\u7a0b\u4e2d\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f53\u4eca\u6570\u636e\u9a71\u52a8\u7684\u65f6\u4ee3\uff0c\u6570\u636e\u5206\u6790\u5df2\u6210\u4e3a\u4f01\u4e1a\u548c\u4e2a\u4eba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u5b9e\u4f8b\uff0c\u4f7f\u7528Python\u5de5\u5177\u8fdb\u884c\u6570\u636e\u5206\u6790\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u67d0\u4e00\u4e1a\u52a1\u95ee\u9898\u7684\u6df1\u5165\u63a2\u7d22\u3002\u6211\u4eec\u5c06\u4ee5\u5206\u6790\u67d0\u7535\u5546\u7f51\u7ad9\u7684\u9500\u91cf\u6570\u636e\u4e3a\u4f8b\uff0c\u4efb\u52a1\u662f\u627e\u51fa\u4e0d\u540c\u4ea7\u54c1\u7c7b\u522b\u7684\u9500\u91cf\u8d8b\u52bf\u548c\u7528\u6237\u8d2d&#8230;<\/p>\n","protected":false},"author":1,"featured_media":624,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12,96,322],"topic":[],"class_list":["post-623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jiushu","tag-python","tag-96","tag-322"],"_links":{"self":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/comments?post=623"}],"version-history":[{"count":1,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/623\/revisions\/626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media\/624"}],"wp:attachment":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media?parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/categories?post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/tags?post=623"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/topic?post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}