{"id":1096395,"date":"2025-01-08T15:00:48","date_gmt":"2025-01-08T07:00:48","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1096395.html"},"modified":"2025-01-08T15:00:51","modified_gmt":"2025-01-08T07:00:51","slug":"python%e5%a6%82%e4%bd%95%e8%af%86%e5%88%ab%e7%89%b9%e5%be%81%e5%80%bc%e5%b9%b6%e6%a0%87%e8%ae%b0-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1096395.html","title":{"rendered":"Python\u5982\u4f55\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211629\/9c402136-4bfa-4d69-86ee-f0f8bd8e7076.webp\" alt=\"Python\u5982\u4f55\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0\" \/><\/p>\n<p><p> <strong>Python\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528NumPy\u5e93\u3001SciPy\u5e93\u3001Pandas\u5e93\u3001\u4ee5\u53ca<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u5e93\u7b49\u3001NumPy\u5e93\u4e2d\u7684<code>eig<\/code>\u51fd\u6570\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5<\/strong>\u3002\u5728\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u8bc6\u522b\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\u3002\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u662f\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u5bf9\u63cf\u8ff0\u77e9\u9635\u7684\u6027\u8d28\u3001\u89e3\u51b3\u7ebf\u6027\u4ee3\u6570\u95ee\u9898\u3001\u4ee5\u53ca\u8fdb\u884c\u6570\u636e\u964d\u7ef4\u7b49\u6709\u7740\u91cd\u8981\u7684\u4f5c\u7528\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001NumPy\u5e93<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u6700\u57fa\u7840\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\u4e4b\u4e00\uff0c\u5e38\u7528\u4e8e\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u3002\u8981\u8bc6\u522b\u7279\u5f81\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u4e2d\u7684<code>eig<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528NumPy\u7684<code>eig<\/code>\u51fd\u6570<\/h4>\n<\/p>\n<p><p>NumPy\u5e93\u4e2d\u7684<code>eig<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u8ba1\u7b97\u65b9\u9635\u7684\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b9\u9635<\/strong><\/h2>\n<p>matrix = np.array([[4, -2],<\/p>\n<p>                   [1,  1]])<\/p>\n<h2><strong>\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/strong><\/h2>\n<p>eigenvalues, eigenvectors = np.linalg.eig(matrix)<\/p>\n<p>print(&quot;\u7279\u5f81\u503c: &quot;, eigenvalues)<\/p>\n<p>print(&quot;\u7279\u5f81\u5411\u91cf: \\n&quot;, eigenvectors)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a2&#215;2\u7684\u65b9\u9635\uff0c\u7136\u540e\u4f7f\u7528<code>np.linalg.eig<\/code>\u51fd\u6570\u8ba1\u7b97\u5176\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002<code>eig<\/code>\u51fd\u6570\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\uff1a\u7b2c\u4e00\u4e2a\u662f\u7279\u5f81\u503c\u6570\u7ec4\uff0c\u7b2c\u4e8c\u4e2a\u662f\u7279\u5f81\u5411\u91cf\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h4>2. \u6807\u8bb0\u7279\u5f81\u503c<\/h4>\n<\/p>\n<p><p>\u6807\u8bb0\u7279\u5f81\u503c\u901a\u5e38\u6d89\u53ca\u6570\u636e\u5904\u7406\u548c\u53ef\u89c6\u5316\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u5c06\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u5b58\u50a8\u5230DataFrame\u4e2d\uff0c\u4ee5\u4fbf\u8fdb\u884c\u8fdb\u4e00\u6b65\u5206\u6790\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efaDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(eigenvectors, columns=[&#39;\u7279\u5f81\u5411\u91cf1&#39;, &#39;\u7279\u5f81\u5411\u91cf2&#39;], index=[&#39;\u7279\u5f81\u503c1&#39;, &#39;\u7279\u5f81\u503c2&#39;])<\/p>\n<p>df[&#39;\u7279\u5f81\u503c&#39;] = eigenvalues<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001SciPy\u5e93<\/h3>\n<\/p>\n<p><p>SciPy\u5e93\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5305\u542b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u51fd\u6570\u548c\u5de5\u5177\u3002SciPy\u4e2d\u7684<code>linalg<\/code>\u6a21\u5757\u4e5f\u53ef\u4ee5\u7528\u6765\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528SciPy\u7684<code>eig<\/code>\u51fd\u6570<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.linalg import eig<\/p>\n<h2><strong>\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/strong><\/h2>\n<p>eigenvalues, eigenvectors = eig(matrix)<\/p>\n<p>print(&quot;\u7279\u5f81\u503c: &quot;, eigenvalues)<\/p>\n<p>print(&quot;\u7279\u5f81\u5411\u91cf: \\n&quot;, eigenvectors)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>SciPy\u7684<code>eig<\/code>\u51fd\u6570\u4f7f\u7528\u65b9\u6cd5\u4e0eNumPy\u7c7b\u4f3c\uff0c\u4f46SciPy\u63d0\u4f9b\u4e86\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\u548c\u9009\u9879\u3002<\/p>\n<\/p>\n<p><h4>2. \u6807\u8bb0\u7279\u5f81\u503c<\/h4>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u5c06\u8ba1\u7b97\u7ed3\u679c\u4fdd\u5b58\u5230DataFrame\u4e2d\uff0c\u4ee5\u4fbf\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001Pandas\u5e93<\/h3>\n<\/p>\n<p><p>Pandas\u5e93\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u5904\u7406\uff0c\u867d\u7136\u5b83\u672c\u8eab\u6ca1\u6709\u76f4\u63a5\u8ba1\u7b97\u7279\u5f81\u503c\u7684\u51fd\u6570\uff0c\u4f46\u53ef\u4ee5\u4e0eNumPy\u6216SciPy\u7ed3\u5408\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Pandas\u5904\u7406\u7279\u5f81\u503c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528NumPy\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/p>\n<p>eigenvalues, eigenvectors = np.linalg.eig(matrix)<\/p>\n<h2><strong>\u521b\u5efaDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(eigenvectors, columns=[&#39;\u7279\u5f81\u5411\u91cf1&#39;, &#39;\u7279\u5f81\u5411\u91cf2&#39;], index=[&#39;\u7279\u5f81\u503c1&#39;, &#39;\u7279\u5f81\u503c2&#39;])<\/p>\n<p>df[&#39;\u7279\u5f81\u503c&#39;] = eigenvalues<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528Pandas\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5bf9\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u8fdb\u884c\u6807\u8bb0\u548c\u5904\u7406\u3002DataFrame\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u4fbf\u4e8e\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u673a\u5668\u5b66\u4e60\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u7279\u5f81\u503c\u5206\u89e3\u548c\u7279\u5f81\u5411\u91cf\u8ba1\u7b97\u5e38\u7528\u4e8e\u4e3b\u6210\u5206\u5206\u6790\uff08PCA\uff09\u7b49\u6570\u636e\u964d\u7ef4\u6280\u672f\u3002Scikit-learn\u5e93\u63d0\u4f9b\u4e86\u6613\u7528\u7684PCA\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Scikit-learn\u7684PCA<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.decomposition import PCA<\/p>\n<h2><strong>\u521b\u5efaPCA\u5bf9\u8c61<\/strong><\/h2>\n<p>pca = PCA(n_components=2)<\/p>\n<h2><strong>\u62df\u5408\u6570\u636e\u5e76\u8fdb\u884cPCA<\/strong><\/h2>\n<p>pca.fit(matrix)<\/p>\n<h2><strong>\u83b7\u53d6\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/strong><\/h2>\n<p>eigenvalues = pca.expl<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ned_variance_<\/p>\n<p>eigenvectors = pca.components_<\/p>\n<p>print(&quot;\u7279\u5f81\u503c: &quot;, eigenvalues)<\/p>\n<p>print(&quot;\u7279\u5f81\u5411\u91cf: \\n&quot;, eigenvectors)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Scikit-learn\u7684PCA\u7c7b\u4e0d\u4ec5\u53ef\u4ee5\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u964d\u7ef4\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7279\u5f81\u503c\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u7406\u89e3\u548c\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u5728\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h4>1. \u6570\u636e\u964d\u7ef4<\/h4>\n<\/p>\n<p><p>\u6570\u636e\u964d\u7ef4\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u91cd\u8981\u6b65\u9aa4\uff0c\u901a\u8fc7PCA\u7b49\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u9ad8\u7ef4\u6570\u636e\u6295\u5f71\u5230\u4f4e\u7ef4\u7a7a\u95f4\uff0c\u4ece\u800c\u51cf\u5c11\u8ba1\u7b97\u590d\u6742\u5ea6\u3002<\/p>\n<\/p>\n<p><h4>2. \u56fe\u50cf\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u7279\u5f81\u503c\u5206\u89e3\u5e38\u7528\u4e8e\u56fe\u50cf\u538b\u7f29\u3001\u53bb\u566a\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>3. \u52a8\u6001\u7cfb\u7edf\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u5728\u52a8\u6001\u7cfb\u7edf\u5206\u6790\u4e2d\u4e5f\u626e\u6f14\u7740\u91cd\u8981\u89d2\u8272\uff0c\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7684\u51e0\u4f55\u89e3\u91ca<\/h3>\n<\/p>\n<p><p>\u4ece\u51e0\u4f55\u89d2\u5ea6\u770b\uff0c\u7279\u5f81\u5411\u91cf\u8868\u793a\u7684\u662f\u77e9\u9635\u53d8\u6362\u540e\u7684\u65b9\u5411\u4e0d\u53d8\u7684\u5411\u91cf\uff0c\u800c\u7279\u5f81\u503c\u8868\u793a\u7684\u662f\u53d8\u6362\u524d\u540e\u5411\u91cf\u957f\u5ea6\u7684\u7f29\u653e\u6bd4\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>1. \u51e0\u4f55\u610f\u4e49<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u5411\u91cf\u63cf\u8ff0\u4e86\u77e9\u9635\u4f5c\u7528\u4e0b\u7684\u56fa\u5b9a\u65b9\u5411\uff0c\u800c\u7279\u5f81\u503c\u63cf\u8ff0\u4e86\u8be5\u65b9\u5411\u4e0a\u7684\u4f38\u7f29\u6bd4\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b9e\u9645\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7684\u51e0\u4f55\u89e3\u91ca\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u6570\u636e\u7ed3\u6784\u3001\u8fdb\u884c\u7ef4\u5ea6\u7f29\u51cf\u3001\u4ee5\u53ca\u8fdb\u884c\u5404\u79cd\u4f18\u5316\u95ee\u9898\u7684\u6c42\u89e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u5982\u7279\u5f81\u503c\u8ba1\u7b97\u7684\u7a33\u5b9a\u6027\u3001\u7279\u5f81\u503c\u7684\u590d\u6570\u5f62\u5f0f\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1. \u7a33\u5b9a\u6027\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6570\u503c\u7a33\u5b9a\u6027\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u9ad8\u7cbe\u5ea6\u7684\u8ba1\u7b97\u5de5\u5177\u6216\u65b9\u6cd5\uff0c\u5982QR\u5206\u89e3\u7b49\u3002<\/p>\n<\/p>\n<p><h4>2. \u590d\u6570\u7279\u5f81\u503c<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u590d\u6570\u7279\u5f81\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u590d\u6570\u6570\u7ec4\u8fdb\u884c\u8ba1\u7b97\uff0c\u5e76\u5728\u7ed3\u679c\u5904\u7406\u4e2d\u6ce8\u610f\u590d\u6570\u90e8\u5206\u7684\u7269\u7406\u610f\u4e49\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0\u662f\u4e00\u9879\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6280\u80fd\uff0cNumPy\u3001SciPy\u3001Pandas\u3001Scikit-learn\u7b49\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u51fd\u6570\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8ba1\u7b97\u548c\u5904\u7406\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u5404\u79cd\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u4efb\u52a1\u4e2d\u3002\u7406\u89e3\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7684\u51e0\u4f55\u610f\u4e49\u548c\u5b9e\u9645\u5e94\u7528\uff0c\u5c06\u6709\u52a9\u4e8e\u6211\u4eec\u66f4\u597d\u5730\u5904\u7406\u9ad8\u7ef4\u6570\u636e\u548c\u590d\u6742\u7cfb\u7edf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u7279\u5f81\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u7279\u5f81\u503c\u7684\u63d0\u53d6\u901a\u5e38\u6d89\u53ca\u4f7f\u7528\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u5e93\uff0c\u4f8b\u5982NumPy\u548cPandas\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528Pandas\u7684DataFrame\u5bf9\u8c61\u6765\u52a0\u8f7d\u548c\u5904\u7406\u6570\u636e\uff0c\u5e76\u5229\u7528NumPy\u7684\u7ebf\u6027\u4ee3\u6570\u6a21\u5757\u6765\u8ba1\u7b97\u7279\u5f81\u503c\u3002\u5bf9\u4e8e\u77e9\u9635\u7684\u7279\u5f81\u503c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>numpy.linalg.eig()<\/code>\u51fd\u6570\uff0c\u5b83\u8fd4\u56de\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002\u786e\u4fdd\u5728\u5904\u7406\u6570\u636e\u65f6\u8fdb\u884c\u9002\u5f53\u7684\u9884\u5904\u7406\uff0c\u4ee5\u63d0\u9ad8\u7279\u5f81\u503c\u63d0\u53d6\u7684\u51c6\u786e\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528Python\u6807\u8bb0\u7279\u5f81\u503c\uff1f<\/strong><br \/>\u6807\u8bb0\u7279\u5f81\u503c\u53ef\u4ee5\u901a\u8fc7\u4e3a\u6bcf\u4e2a\u7279\u5f81\u503c\u5206\u914d\u4e00\u4e2a\u6807\u7b7e\u6216\u7c7b\u522b\u6765\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>apply()<\/code>\u51fd\u6570\u7ed3\u5408\u81ea\u5b9a\u4e49\u7684\u6807\u8bb0\u51fd\u6570\uff0c\u6216\u4f7f\u7528Scikit-learn\u7684<code>LabelEncoder<\/code>\u7c7b\u6765\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\u3002\u786e\u4fdd\u5728\u6807\u8bb0\u8fc7\u7a0b\u4e2d\u8003\u8651\u7279\u5f81\u7684\u6027\u8d28\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684\u5206\u6790\u548c\u5efa\u6a21\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5904\u7406\u7f3a\u5931\u503c\u5bf9\u7279\u5f81\u503c\u63d0\u53d6\u6709\u4f55\u5f71\u54cd\uff1f<\/strong><br \/>\u7f3a\u5931\u503c\u4f1a\u5bf9\u7279\u5f81\u503c\u63d0\u53d6\u4ea7\u751f\u663e\u8457\u5f71\u54cd\uff0c\u53ef\u80fd\u5bfc\u81f4\u8ba1\u7b97\u7ed3\u679c\u4e0d\u51c6\u786e\u6216\u6a21\u578b\u6027\u80fd\u4e0b\u964d\u3002\u4e3a\u4e86\u6709\u6548\u5904\u7406\u7f3a\u5931\u503c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>fillna()<\/code>\u65b9\u6cd5\u6765\u586b\u5145\u7f3a\u5931\u6570\u636e\uff0c\u6216\u8005<code>dropna()<\/code>\u65b9\u6cd5\u6765\u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c\u6216\u5217\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\u65f6\uff0c\u8003\u8651\u4f7f\u7528\u63d2\u503c\u6cd5\u6216\u5176\u4ed6\u8865\u5168\u6280\u672f\uff0c\u4ee5\u4fdd\u6301\u6570\u636e\u96c6\u7684\u5b8c\u6574\u6027\u548c\u7279\u5f81\u503c\u7684\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8bc6\u522b\u7279\u5f81\u503c\u5e76\u6807\u8bb0\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528NumPy\u5e93\u3001SciPy\u5e93\u3001Pandas\u5e93\u3001\u4ee5\u53ca\u673a\u5668\u5b66\u4e60\u5e93\u7b49\u3001Num [&hellip;]","protected":false},"author":3,"featured_media":1096401,"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\/1096395"}],"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=1096395"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1096395\/revisions"}],"predecessor-version":[{"id":1096402,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1096395\/revisions\/1096402"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1096401"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1096395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1096395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1096395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}