{"id":1128367,"date":"2025-01-08T20:19:50","date_gmt":"2025-01-08T12:19:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1128367.html"},"modified":"2025-01-08T20:19:52","modified_gmt":"2025-01-08T12:19:52","slug":"python%e5%a6%82%e4%bd%95%e6%b1%82%e4%b8%80%e7%bb%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e7%9a%84%e5%9d%87%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1128367.html","title":{"rendered":"python\u5982\u4f55\u6c42\u4e00\u7ec4\u6570\u636e\u7c7b\u7684\u5747\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095111\/8255dacd-6ed8-4232-81b1-b4d906c61b99.webp\" alt=\"python\u5982\u4f55\u6c42\u4e00\u7ec4\u6570\u636e\u7c7b\u7684\u5747\u503c\" \/><\/p>\n<p><p> <strong>Python\u6c42\u4e00\u7ec4\u6570\u636e\u7c7b\u7684\u5747\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001Numpy\u5e93\u3001Pandas\u5e93\u7b49\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u9009\u62e9\u53d6\u51b3\u4e8e\u5177\u4f53\u5e94\u7528\u573a\u666f<\/strong>\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u65b9\u6cd5\uff0c\u5e76\u5bf9\u5176\u4e2d\u4e00\u79cd\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8ba1\u7b97\u5747\u503c<\/h3>\n<\/p>\n<p><p>Python\u7684\u5185\u7f6e\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u7528\u6765\u8ba1\u7b97\u6570\u636e\u96c6\u7684\u5747\u503c\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u7528\u4e8e\u8f83\u5c0f\u7684\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u7528\u5185\u7f6e\u51fd\u6570\u6c42\u5747\u503c<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u5185\u7f6e\u51fd\u6570\u6c42\u5747\u503c\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5]<\/p>\n<p>mean = sum(data) \/ len(data)<\/p>\n<p>print(mean)  # \u8f93\u51fa 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5148\u5c06\u6570\u636e\u5b58\u5165\u4e00\u4e2a\u5217\u8868 <code>data<\/code>\uff0c\u7136\u540e\u4f7f\u7528 <code>sum()<\/code> \u51fd\u6570\u8ba1\u7b97\u6570\u636e\u7684\u603b\u548c\uff0c\u518d\u7528 <code>len()<\/code> \u51fd\u6570\u83b7\u53d6\u6570\u636e\u7684\u957f\u5ea6\uff0c\u6700\u540e\u5c06\u603b\u548c\u9664\u4ee5\u957f\u5ea6\u5f97\u5230\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u4f18\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5355\u6613\u7528\uff0c\u4ee3\u7801\u7b80\u6d01\u3002<\/li>\n<li>\u4e0d\u9700\u8981\u4f9d\u8d56\u5916\u90e8\u5e93\uff0c\u9002\u5408\u521d\u5b66\u8005\u548c\u5c0f\u578b\u9879\u76ee\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u8ba1\u7b97\u6548\u7387\u8f83\u4f4e\u3002<\/li>\n<li>\u529f\u80fd\u6709\u9650\uff0c\u65e0\u6cd5\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Numpy\u5e93\u8ba1\u7b97\u5747\u503c<\/h3>\n<\/p>\n<p><p>Numpy\u662fPython\u4e2d\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u7684\u5f3a\u5927\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\u529f\u80fd\u3002\u4f7f\u7528Numpy\u8ba1\u7b97\u5747\u503c\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u8ba1\u7b97\u6548\u7387\u9ad8\uff0c\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u5b89\u88c5Numpy<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Numpy\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u7528Numpy\u8ba1\u7b97\u5747\u503c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>data = [1, 2, 3, 4, 5]<\/p>\n<p>mean = np.mean(data)<\/p>\n<p>print(mean)  # \u8f93\u51fa 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165Numpy\u5e93\uff0c\u7136\u540e\u5c06\u6570\u636e\u5b58\u5165\u4e00\u4e2a\u5217\u8868 <code>data<\/code>\uff0c\u63a5\u7740\u4f7f\u7528 <code>np.mean()<\/code> \u51fd\u6570\u76f4\u63a5\u8ba1\u7b97\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>2.3 \u4f18\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u8ba1\u7b97\u6548\u7387\u9ad8\uff0c\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<\/li>\n<li>\u529f\u80fd\u4e30\u5bcc\uff0c\u53ef\u4ee5\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u548c\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u3002<\/li>\n<li>\u6613\u4e8e\u4e0e\u5176\u4ed6\u79d1\u5b66\u8ba1\u7b97\u5e93\uff08\u5982Pandas\u3001SciPy\uff09\u96c6\u6210\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165\u5916\u90e8\u5e93\uff0c\u5bf9\u521d\u5b66\u8005\u4e0d\u592a\u53cb\u597d\u3002<\/li>\n<li>\u5bf9\u4e8e\u975e\u5e38\u5c0f\u7684\u6570\u636e\u96c6\uff0c\u53ef\u80fd\u663e\u5f97\u8fc7\u4e8e\u590d\u6742\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u4f7f\u7528Pandas\u5e93\u8ba1\u7b97\u5747\u503c<\/h3>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u5904\u7406\u6570\u636e\u5206\u6790\u7684\u5f3a\u5927\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\u3002\u4f7f\u7528Pandas\u8ba1\u7b97\u5747\u503c\u975e\u5e38\u65b9\u4fbf\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5Pandas<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Pandas\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u7528Pandas\u8ba1\u7b97\u5747\u503c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = [1, 2, 3, 4, 5]<\/p>\n<p>df = pd.DataFrame(data, columns=[&#39;Values&#39;])<\/p>\n<p>mean = df[&#39;Values&#39;].mean()<\/p>\n<p>print(mean)  # \u8f93\u51fa 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165Pandas\u5e93\uff0c\u7136\u540e\u5c06\u6570\u636e\u5b58\u5165\u4e00\u4e2a\u5217\u8868 <code>data<\/code>\uff0c\u63a5\u7740\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u4e00\u4e2aDataFrame\u5bf9\u8c61 <code>df<\/code>\uff0c\u6700\u540e\u4f7f\u7528 <code>df[&#39;Values&#39;].mean()<\/code> \u51fd\u6570\u8ba1\u7b97\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>3.3 \u4f18\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\u3002<\/li>\n<li>\u6613\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\uff0c\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\u7684\u8bfb\u53d6\u548c\u5199\u5165\u3002<\/li>\n<li>\u4e0e\u5176\u4ed6\u79d1\u5b66\u8ba1\u7b97\u5e93\uff08\u5982Numpy\u3001SciPy\uff09\u96c6\u6210\u826f\u597d\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165\u5916\u90e8\u5e93\uff0c\u5bf9\u521d\u5b66\u8005\u4e0d\u592a\u53cb\u597d\u3002<\/li>\n<li>\u5bf9\u4e8e\u975e\u5e38\u5c0f\u7684\u6570\u636e\u96c6\uff0c\u53ef\u80fd\u663e\u5f97\u8fc7\u4e8e\u590d\u6742\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u4f7f\u7528\u7edf\u8ba1\u5e93\u8ba1\u7b97\u5747\u503c<\/h3>\n<\/p>\n<p><p>Python\u7684 <code>statistics<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u5e38\u7528\u7684\u7edf\u8ba1\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u8ba1\u7b97\u5747\u503c\u7b49\u7edf\u8ba1\u91cf\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u7528\u7edf\u8ba1\u5e93\u8ba1\u7b97\u5747\u503c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import statistics<\/p>\n<p>data = [1, 2, 3, 4, 5]<\/p>\n<p>mean = statistics.mean(data)<\/p>\n<p>print(mean)  # \u8f93\u51fa 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165 <code>statistics<\/code> \u6a21\u5757\uff0c\u7136\u540e\u5c06\u6570\u636e\u5b58\u5165\u4e00\u4e2a\u5217\u8868 <code>data<\/code>\uff0c\u63a5\u7740\u4f7f\u7528 <code>statistics.mean()<\/code> \u51fd\u6570\u76f4\u63a5\u8ba1\u7b97\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>4.2 \u4f18\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5355\u6613\u7528\uff0c\u4ee3\u7801\u7b80\u6d01\u3002<\/li>\n<li>\u4e0d\u9700\u8981\u4f9d\u8d56\u5916\u90e8\u5e93\uff0c\u9002\u5408\u521d\u5b66\u8005\u548c\u5c0f\u578b\u9879\u76ee\u3002<\/li>\n<li>\u63d0\u4f9b\u4e86\u5176\u4ed6\u5e38\u7528\u7684\u7edf\u8ba1\u51fd\u6570\uff0c\u5982\u4e2d\u4f4d\u6570\u3001\u6807\u51c6\u5dee\u7b49\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>:<\/p>\n<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u8ba1\u7b97\u6548\u7387\u8f83\u4f4e\u3002<\/li>\n<li>\u529f\u80fd\u6709\u9650\uff0c\u65e0\u6cd5\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u591a\u79cd\u4f7f\u7528Python\u8ba1\u7b97\u4e00\u7ec4\u6570\u636e\u7c7b\u7684\u5747\u503c\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001Numpy\u5e93\u3001Pandas\u5e93\u548c\u7edf\u8ba1\u5e93\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/strong>\uff1a\u9002\u5408\u521d\u5b66\u8005\u548c\u5c0f\u578b\u9879\u76ee\uff0c\u4ee3\u7801\u7b80\u6d01\u4f46\u8ba1\u7b97\u6548\u7387\u8f83\u4f4e\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Numpy\u5e93<\/strong>\uff1a\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\uff0c\u8ba1\u7b97\u6548\u7387\u9ad8\uff0c\u529f\u80fd\u4e30\u5bcc\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Pandas\u5e93<\/strong>\uff1a\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\uff0c\u529f\u80fd\u5f3a\u5927\uff0c\u6613\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u7edf\u8ba1\u5e93<\/strong>\uff1a\u9002\u5408\u521d\u5b66\u8005\u548c\u5c0f\u578b\u9879\u76ee\uff0c\u4ee3\u7801\u7b80\u6d01\uff0c\u63d0\u4f9b\u4e86\u5176\u4ed6\u5e38\u7528\u7684\u7edf\u8ba1\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u6570\u636e\u7684\u5747\u503c\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8ba1\u7b97\u4e00\u7ec4\u6570\u503c\u6570\u636e\u7684\u5747\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>sum()<\/code>\u51fd\u6570\u4e0e<code>len()<\/code>\u51fd\u6570\u7ed3\u5408\u8ba1\u7b97\u5747\u503c\u3002\u5177\u4f53\u6b65\u9aa4\u4e3a\uff1a\u5c06\u6570\u636e\u5217\u8868\u7684\u6240\u6709\u5143\u7d20\u76f8\u52a0\uff0c\u518d\u9664\u4ee5\u5143\u7d20\u7684\u6570\u91cf\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">data = [10, 20, 30, 40, 50]\nmean = sum(data) \/ len(data)\nprint(mean)  # \u8f93\u51fa\u5747\u503c\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u4f7f\u7528NumPy\u5e93\u7684<code>mean()<\/code>\u51fd\u6570\u4e5f\u80fd\u66f4\u7b80\u4fbf\u5730\u8ba1\u7b97\u5747\u503c\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\u6765\u8ba1\u7b97\u5747\u503c\uff1f<\/strong><br \/>\u5f53\u6570\u636e\u96c6\u4e2d\u5b58\u5728\u7f3a\u5931\u503c\u65f6\uff0c\u4f7f\u7528<code>pandas<\/code>\u5e93\u80fd\u591f\u6709\u6548\u5730\u5904\u7406\u3002\u5728\u8ba1\u7b97\u5747\u503c\u4e4b\u524d\uff0c\u53ef\u4ee5\u5229\u7528<code>dropna()<\/code>\u65b9\u6cd5\u53bb\u6389\u7f3a\u5931\u503c\uff0c\u6216\u8005\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u586b\u5145\u7f3a\u5931\u503c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>pandas<\/code>\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = pd.Series([10, 20, None, 40, 50])\nmean = data.dropna().mean()  # \u8ba1\u7b97\u5747\u503c\uff0c\u5ffd\u7565\u7f3a\u5931\u503c\nprint(mean)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u8ba1\u7b97\u7684\u5747\u503c\u51c6\u786e\u53cd\u6620\u53ef\u7528\u6570\u636e\u3002<\/p>\n<p><strong>Python\u4e2d\u5982\u4f55\u5904\u7406\u975e\u6570\u503c\u6570\u636e\u4ee5\u6c42\u5747\u503c\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5305\u542b\u975e\u6570\u503c\u6570\u636e\u7684\u96c6\u5408\u65f6\uff0c\u9996\u5148\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u3002\u53ef\u4ee5\u901a\u8fc7<code>pandas<\/code>\u5e93\u4e2d\u7684<code>to_numeric()<\/code>\u65b9\u6cd5\u5c06\u6570\u636e\u8f6c\u5316\u4e3a\u6570\u503c\u7c7b\u578b\uff0c\u540c\u65f6\u8bbe\u7f6e<code>errors=&#39;coerce&#39;<\/code>\u53c2\u6570\u5c06\u65e0\u6cd5\u8f6c\u6362\u7684\u503c\u8f6c\u4e3aNaN\u3002\u5b8c\u6210\u6570\u636e\u6e05\u6d17\u540e\uff0c\u518d\u8fdb\u884c\u5747\u503c\u8ba1\u7b97\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = pd.Series([&#39;10&#39;, &#39;20&#39;, &#39;30&#39;, &#39;not a number&#39;, &#39;50&#39;])\nnumeric_data = pd.to_numeric(data, errors=&#39;coerce&#39;)\nmean = numeric_data.mean()  # \u8ba1\u7b97\u5747\u503c\nprint(mean)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u5f97\u5373\u4fbf\u6570\u636e\u4e2d\u5305\u542b\u975e\u6570\u503c\u9879\uff0c\u4e5f\u80fd\u987a\u5229\u8ba1\u7b97\u51fa\u5747\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u6c42\u4e00\u7ec4\u6570\u636e\u7c7b\u7684\u5747\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001Numpy\u5e93\u3001Pandas\u5e93\u7b49\u3002\u8fd9\u4e9b\u65b9 [&hellip;]","protected":false},"author":3,"featured_media":1128375,"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\/1128367"}],"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=1128367"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128367\/revisions"}],"predecessor-version":[{"id":1128380,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128367\/revisions\/1128380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1128375"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1128367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1128367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1128367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}