{"id":1126411,"date":"2025-01-08T20:01:00","date_gmt":"2025-01-08T12:01:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1126411.html"},"modified":"2025-01-08T20:01:03","modified_gmt":"2025-01-08T12:01:03","slug":"%e5%88%a9%e7%94%a8python%e5%a6%82%e4%bd%95%e7%bb%9f%e8%ae%a1%e4%b8%80%e4%b8%aa%e8%a1%a8%e5%90%84%e4%b8%aa%e6%83%85%e5%86%b5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1126411.html","title":{"rendered":"\u5229\u7528python\u5982\u4f55\u7edf\u8ba1\u4e00\u4e2a\u8868\u5404\u4e2a\u60c5\u51b5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090739\/8398f8d5-f8f1-43c7-8804-446901b9a877.webp\" alt=\"\u5229\u7528python\u5982\u4f55\u7edf\u8ba1\u4e00\u4e2a\u8868\u5404\u4e2a\u60c5\u51b5\" \/><\/p>\n<p><p> <strong>\u5229\u7528Python\u5982\u4f55\u7edf\u8ba1\u4e00\u4e2a\u8868\u5404\u4e2a\u60c5\u51b5<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u7edf\u8ba1\u4e00\u4e2a\u8868\u7684\u5404\u4e2a\u60c5\u51b5\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u8bfb\u53d6\u6570\u636e\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u5206\u6790\u3001\u6570\u636e\u53ef\u89c6\u5316\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u8bfb\u53d6\u6570\u636e<\/strong> \u548c <strong>\u6570\u636e\u5206\u6790<\/strong> \u662f\u6700\u4e3a\u5173\u952e\u7684\u6b65\u9aa4\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u5229\u7528Python\u7edf\u8ba1\u4e00\u4e2a\u8868\u7684\u5404\u4e2a\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8bfb\u53d6\u6570\u636e<\/p>\n<\/p>\n<p><p>\u8981\u7edf\u8ba1\u4e00\u4e2a\u8868\u683c\u4e2d\u7684\u5404\u4e2a\u60c5\u51b5\uff0c\u7b2c\u4e00\u6b65\u662f\u8bfb\u53d6\u6570\u636e\u3002Python\u6709\u591a\u4e2a\u5e93\u53ef\u4ee5\u7528\u6765\u5904\u7406\u8fd9\u9879\u5de5\u4f5c\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>pandas<\/code>\u5e93\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u8bfb\u53d6\u5404\u79cd\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u5305\u62ecCSV\u3001Excel\u3001SQL\u6570\u636e\u5e93\u7b49\u3002\u4e0b\u9762\u662f\u8bfb\u53d6CSV\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;your_file.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06CSV\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u8bfb\u53d6\u5230\u4e00\u4e2a<code>DataFrame<\/code>\u5bf9\u8c61\u4e2d\u3002<code>DataFrame<\/code>\u662f<code>pandas<\/code>\u5e93\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7c7b\u4f3c\u4e8eExcel\u4e2d\u7684\u8868\u683c\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u6570\u636e\u6e05\u6d17<\/p>\n<\/p>\n<p><p>\u5728\u8bfb\u53d6\u6570\u636e\u4e4b\u540e\uff0c\u901a\u5e38\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u3002\u6570\u636e\u6e05\u6d17\u7684\u76ee\u7684\u662f\u53bb\u9664\u6216\u4fee\u6b63\u6570\u636e\u4e2d\u7684\u9519\u8bef\u3001\u7f3a\u5931\u503c\u548c\u91cd\u590d\u503c\u3002\u5e38\u89c1\u7684\u6e05\u6d17\u64cd\u4f5c\u5305\u62ec\u5220\u9664\u7f3a\u5931\u503c\u3001\u586b\u5145\u7f3a\u5931\u503c\u3001\u5220\u9664\u91cd\u590d\u503c\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6570\u636e\u6e05\u6d17\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c<\/p>\n<p>data = data.dropna()<\/p>\n<h2><strong>\u7528\u6307\u5b9a\u503c\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>data = data.fillna(value=0)<\/p>\n<h2><strong>\u5220\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>data = data.drop_duplicates()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6570\u636e\u6e05\u6d17<\/strong> \u662f\u6570\u636e\u5206\u6790\u4e2d\u7684\u91cd\u8981\u6b65\u9aa4\uff0c\u56e0\u4e3a\u4e0d\u5e72\u51c0\u7684\u6570\u636e\u4f1a\u5f71\u54cd\u540e\u7eed\u7684\u5206\u6790\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u6570\u636e\u5206\u6790<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u6e05\u6d17\u4e4b\u540e\uff0c\u4fbf\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002\u6570\u636e\u5206\u6790\u7684\u76ee\u7684\u662f\u4ece\u6570\u636e\u4e2d\u63d0\u53d6\u6709\u7528\u7684\u4fe1\u606f\u548c\u6a21\u5f0f\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u7edf\u8ba1\u8868\u683c\u4e2d\u7684\u5404\u4e2a\u60c5\u51b5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6570\u636e\u5206\u6790\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><p><strong>1. \u7edf\u8ba1\u63cf\u8ff0<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7edf\u8ba1\u63cf\u8ff0\u53ef\u4ee5\u83b7\u53d6\u6570\u636e\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f\uff0c\u5982\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u3001\u6807\u51c6\u5dee\u7b49\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86<code>describe<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5feb\u901f\u83b7\u53d6\u8fd9\u4e9b\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u6570\u636e\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p>statistics = data.describe()<\/p>\n<p>print(statistics)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>2. \u5206\u7ec4\u7edf\u8ba1<\/strong><\/p>\n<\/p>\n<p><p>\u5206\u7ec4\u7edf\u8ba1\u662f\u6307\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u5206\u7ec4\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86<code>groupby<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5206\u7ec4\u7edf\u8ba1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6309\u67d0\u5217\u8fdb\u884c\u5206\u7ec4\u5e76\u7edf\u8ba1\u6bcf\u4e2a\u5206\u7ec4\u4e2d\u6570\u636e\u6570\u91cf\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6309\u67d0\u5217\u8fdb\u884c\u5206\u7ec4\u5e76\u7edf\u8ba1\u6bcf\u4e2a\u5206\u7ec4\u7684\u6570\u636e\u6570\u91cf<\/p>\n<p>grouped_data = data.groupby(&#39;column_name&#39;).size()<\/p>\n<p>print(grouped_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>3. \u4ea4\u53c9\u8868\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u4ea4\u53c9\u8868\u5206\u6790\u662f\u6307\u5bf9\u4e24\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u8fdb\u884c\u4ea4\u53c9\u5206\u6790\uff0c\u901a\u5e38\u7528\u4e8e\u5206\u6790\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86<code>crosstab<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4ea4\u53c9\u8868\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4ea4\u53c9\u8868<\/p>\n<p>cross_tab = pd.crosstab(data[&#39;column1&#39;], data[&#39;column2&#39;])<\/p>\n<p>print(cross_tab)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6570\u636e\u53ef\u89c6\u5316<\/p>\n<\/p>\n<p><p>\u6570\u636e\u53ef\u89c6\u5316\u662f\u6307\u5c06\u6570\u636e\u4ee5\u56fe\u8868\u7684\u5f62\u5f0f\u5c55\u793a\u51fa\u6765\uff0c\u4ee5\u4fbf\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u6570\u636e\u3002Python\u6709\u591a\u4e2a\u5e93\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>matplotlib<\/code>\u548c<code>seaborn<\/code>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6570\u636e\u53ef\u89c6\u5316\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><p><strong>1. \u67f1\u72b6\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u67f1\u72b6\u56fe\u662f\u4e00\u79cd\u5e38\u7528\u7684\u7edf\u8ba1\u56fe\u8868\uff0c\u7528\u4e8e\u5c55\u793a\u5206\u7c7b\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>matplotlib<\/code>\u7ed8\u5236\u67f1\u72b6\u56fe\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236\u67f1\u72b6\u56fe<\/strong><\/h2>\n<p>data[&#39;column_name&#39;].value_counts().plot(kind=&#39;bar&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>2. \u76f4\u65b9\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u76f4\u65b9\u56fe\u662f\u4e00\u79cd\u5e38\u7528\u7684\u7edf\u8ba1\u56fe\u8868\uff0c\u7528\u4e8e\u5c55\u793a\u6570\u503c\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>matplotlib<\/code>\u7ed8\u5236\u76f4\u65b9\u56fe\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7ed8\u5236\u76f4\u65b9\u56fe<\/p>\n<p>data[&#39;column_name&#39;].plot(kind=&#39;hist&#39;, bins=50)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>3. \u7bb1\u7ebf\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u7bb1\u7ebf\u56fe\u662f\u4e00\u79cd\u5e38\u7528\u7684\u7edf\u8ba1\u56fe\u8868\uff0c\u7528\u4e8e\u5c55\u793a\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u548c\u5f02\u5e38\u503c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>seaborn<\/code>\u7ed8\u5236\u7bb1\u7ebf\u56fe\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<h2><strong>\u7ed8\u5236\u7bb1\u7ebf\u56fe<\/strong><\/h2>\n<p>sns.boxplot(x=data[&#39;column_name&#39;])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528Python\u5bf9\u8868\u683c\u6570\u636e\u8fdb\u884c\u5168\u9762\u7684\u7edf\u8ba1\u5206\u6790\u548c\u53ef\u89c6\u5316\u5c55\u793a\u3002\u8fd9\u4e0d\u4ec5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u4e3a\u51b3\u7b56\u63d0\u4f9b\u6709\u529b\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u6848\u4f8b\u5206\u6790<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5229\u7528Python\u7edf\u8ba1\u4e00\u4e2a\u8868\u7684\u5404\u4e2a\u60c5\u51b5\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u6848\u4f8b\u8fdb\u884c\u8be6\u7ec6\u8bf4\u660e\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u5b66\u751f\u6210\u7ee9\u7684\u6570\u636e\u8868\u683c\uff0c\u8868\u683c\u5305\u62ec\u4ee5\u4e0b\u5217\uff1a\u5b66\u751f\u59d3\u540d\u3001\u6027\u522b\u3001\u5e74\u9f84\u3001\u6570\u5b66\u6210\u7ee9\u3001\u82f1\u8bed\u6210\u7ee9\u3001\u79d1\u5b66\u6210\u7ee9\u3002\u6211\u4eec\u9700\u8981\u7edf\u8ba1\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5404\u79d1\u6210\u7ee9\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>\u6309\u6027\u522b\u5206\u7ec4\u7684\u5404\u79d1\u6210\u7ee9\u5e73\u5747\u503c<\/li>\n<li>\u5404\u5e74\u9f84\u6bb5\u7684\u5b66\u751f\u4eba\u6570<\/li>\n<li>\u6570\u5b66\u6210\u7ee9\u4e0e\u82f1\u8bed\u6210\u7ee9\u4e4b\u95f4\u7684\u5173\u7cfb<\/li>\n<li>\u5404\u79d1\u6210\u7ee9\u7684\u5206\u5e03\u60c5\u51b5<\/li>\n<\/ol>\n<p><p><strong>\u6b65\u9aa41\uff1a\u8bfb\u53d6\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;students_scores.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6b65\u9aa42\uff1a\u6570\u636e\u6e05\u6d17<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c<\/p>\n<p>data = data.dropna()<\/p>\n<h2><strong>\u5220\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>data = data.drop_duplicates()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6b65\u9aa43\uff1a\u6570\u636e\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p><strong>1. \u5404\u79d1\u6210\u7ee9\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u5404\u79d1\u6210\u7ee9\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p>statistics = data[[&#39;\u6570\u5b66\u6210\u7ee9&#39;, &#39;\u82f1\u8bed\u6210\u7ee9&#39;, &#39;\u79d1\u5b66\u6210\u7ee9&#39;]].describe()<\/p>\n<p>print(statistics)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>2. \u6309\u6027\u522b\u5206\u7ec4\u7684\u5404\u79d1\u6210\u7ee9\u5e73\u5747\u503c<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6309\u6027\u522b\u5206\u7ec4\u5e76\u8ba1\u7b97\u5404\u79d1\u6210\u7ee9\u7684\u5e73\u5747\u503c<\/p>\n<p>grouped_data = data.groupby(&#39;\u6027\u522b&#39;)[[&#39;\u6570\u5b66\u6210\u7ee9&#39;, &#39;\u82f1\u8bed\u6210\u7ee9&#39;, &#39;\u79d1\u5b66\u6210\u7ee9&#39;]].mean()<\/p>\n<p>print(grouped_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>3. \u5404\u5e74\u9f84\u6bb5\u7684\u5b66\u751f\u4eba\u6570<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6309\u5e74\u9f84\u5206\u7ec4\u5e76\u7edf\u8ba1\u6bcf\u4e2a\u5e74\u9f84\u6bb5\u7684\u5b66\u751f\u4eba\u6570<\/p>\n<p>age_distribution = data[&#39;\u5e74\u9f84&#39;].value_counts()<\/p>\n<p>print(age_distribution)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>4. \u6570\u5b66\u6210\u7ee9\u4e0e\u82f1\u8bed\u6210\u7ee9\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u6570\u5b66\u6210\u7ee9\u4e0e\u82f1\u8bed\u6210\u7ee9\u4e4b\u95f4\u7684\u76f8\u5173\u7cfb\u6570<\/p>\n<p>correlation = data[&#39;\u6570\u5b66\u6210\u7ee9&#39;].corr(data[&#39;\u82f1\u8bed\u6210\u7ee9&#39;])<\/p>\n<p>print(correlation)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>5. \u5404\u79d1\u6210\u7ee9\u7684\u5206\u5e03\u60c5\u51b5<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236\u5404\u79d1\u6210\u7ee9\u7684\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>data[&#39;\u6570\u5b66\u6210\u7ee9&#39;].plot(kind=&#39;hist&#39;, bins=50, title=&#39;\u6570\u5b66\u6210\u7ee9\u5206\u5e03&#39;)<\/p>\n<p>plt.show()<\/p>\n<p>data[&#39;\u82f1\u8bed\u6210\u7ee9&#39;].plot(kind=&#39;hist&#39;, bins=50, title=&#39;\u82f1\u8bed\u6210\u7ee9\u5206\u5e03&#39;)<\/p>\n<p>plt.show()<\/p>\n<p>data[&#39;\u79d1\u5b66\u6210\u7ee9&#39;].plot(kind=&#39;hist&#39;, bins=50, title=&#39;\u79d1\u5b66\u6210\u7ee9\u5206\u5e03&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u7cfb\u7edf\u5730\u7edf\u8ba1\u5b66\u751f\u6210\u7ee9\u8868\u4e2d\u7684\u5404\u4e2a\u60c5\u51b5\uff0c\u5e76\u901a\u8fc7\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u624b\u6bb5\u6df1\u5165\u7406\u89e3\u6570\u636e\u3002\u8fd9\u6837\u4e0d\u4ec5\u53ef\u4ee5\u53d1\u73b0\u6570\u636e\u4e2d\u7684\u89c4\u5f8b\uff0c\u8fd8\u53ef\u4ee5\u4e3a\u6559\u80b2\u51b3\u7b56\u63d0\u4f9b\u6709\u529b\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5229\u7528Python\u7edf\u8ba1\u4e00\u4e2a\u8868\u7684\u5404\u4e2a\u60c5\u51b5\u4e3b\u8981\u5305\u62ec\u8bfb\u53d6\u6570\u636e\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u5206\u6790\u548c\u6570\u636e\u53ef\u89c6\u5316\u56db\u4e2a\u6b65\u9aa4\u3002\u901a\u8fc7<code>pandas<\/code>\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u8bfb\u53d6\u548c\u6e05\u6d17\uff0c\u5e76\u5229\u7528\u5176\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002\u901a\u8fc7<code>matplotlib<\/code>\u548c<code>seaborn<\/code>\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u636e\u4ee5\u56fe\u8868\u7684\u5f62\u5f0f\u5c55\u793a\u51fa\u6765\uff0c\u4f7f\u6570\u636e\u66f4\u52a0\u76f4\u89c2\u548c\u6613\u4e8e\u7406\u89e3\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u901a\u8fc7\u6848\u4f8b\u5206\u6790\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u638c\u63e1\u5982\u4f55\u5229\u7528Python\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u7edf\u8ba1\u8868\u683c\u4e2d\u7684\u4e0d\u540c\u60c5\u51b5\uff1f<\/strong><br \/>\u4f7f\u7528Python\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u901a\u5e38\u53ef\u4ee5\u5229\u7528Pandas\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5c06\u6570\u636e\u52a0\u8f7d\u5230DataFrame\u4e2d\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u65b9\u6cd5\u5982<code>groupby()<\/code>\u3001<code>value_counts()<\/code>\u548c<code>describe()<\/code>\u6765\u7edf\u8ba1\u4e0d\u540c\u7684\u60c5\u51b5\u3002\u8fd9\u6837\u53ef\u4ee5\u8f7b\u677e\u4e86\u89e3\u6570\u636e\u7684\u5206\u5e03\u548c\u7279\u5f81\u3002<\/p>\n<p><strong>\u5728\u7edf\u8ba1\u8868\u683c\u6570\u636e\u65f6\uff0c\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u4e4b\u524d\uff0c\u5904\u7406\u7f3a\u5931\u503c\u662f\u5f88\u91cd\u8981\u7684\u4e00\u6b65\u3002Pandas\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5904\u7406\u7f3a\u5931\u503c\uff0c\u4f8b\u5982<code>dropna()<\/code>\u53ef\u4ee5\u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c\uff0c\u800c<code>fillna()<\/code>\u53ef\u4ee5\u7528\u7279\u5b9a\u503c\u66ff\u4ee3\u7f3a\u5931\u503c\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u63d2\u503c\u65b9\u6cd5\u6765\u586b\u8865\u7f3a\u5931\u6570\u636e\uff0c\u4ee5\u786e\u4fdd\u7edf\u8ba1\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u548c\u5206\u6790\uff1f<\/strong><br \/>\u9664\u4e86Pandas\uff0cPython\u8fd8\u6709\u591a\u4e2a\u5e93\u53ef\u7528\u4e8e\u6570\u636e\u7edf\u8ba1\u548c\u5206\u6790\u3002\u4f8b\u5982\uff0cNumPy\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u5b66\u8fd0\u7b97\u529f\u80fd\uff0cMatplotlib\u548cSeaborn\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\uff0cSciPy\u5219\u63d0\u4f9b\u4e86\u8bb8\u591a\u7edf\u8ba1\u5b66\u5de5\u5177\u3002\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u7ec4\u5408\u4f7f\u7528\uff0c\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\uff0c\u5e2e\u52a9\u7528\u6237\u6df1\u5165\u7406\u89e3\u6570\u636e\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5229\u7528Python\u5982\u4f55\u7edf\u8ba1\u4e00\u4e2a\u8868\u5404\u4e2a\u60c5\u51b5 \u4f7f\u7528Python\u7edf\u8ba1\u4e00\u4e2a\u8868\u7684\u5404\u4e2a\u60c5\u51b5\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u8bfb\u53d6\u6570\u636e\u3001\u6570\u636e\u6e05\u6d17 [&hellip;]","protected":false},"author":3,"featured_media":1126422,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126411"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1126411"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126411\/revisions"}],"predecessor-version":[{"id":1126425,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126411\/revisions\/1126425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1126422"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1126411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1126411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1126411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}