{"id":1141881,"date":"2025-01-08T22:34:53","date_gmt":"2025-01-08T14:34:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1141881.html"},"modified":"2025-01-08T22:34:55","modified_gmt":"2025-01-08T14:34:55","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%8e%bb%e9%87%8d%e5%8f%96%e6%95%b0%e6%8d%ae%e7%9a%84%e6%9f%90%e4%b8%80%e5%88%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1141881.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u53bb\u91cd\u53d6\u6570\u636e\u7684\u67d0\u4e00\u5217"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104457\/45b5d73a-52c0-4a26-bad1-888826807748.webp\" alt=\"python\u4e2d\u5982\u4f55\u53bb\u91cd\u53d6\u6570\u636e\u7684\u67d0\u4e00\u5217\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u53bb\u91cd\u53d6\u6570\u636e\u7684\u67d0\u4e00\u5217\u6709\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528Pandas\u3001\u4f7f\u7528\u96c6\u5408\u3001\u4f7f\u7528Numpy\u7b49\u3002<\/strong>\u5176\u4e2d\uff0c<strong>Pandas<\/strong> \u662f\u6700\u5e38\u89c1\u548c\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e13\u95e8\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002<strong>\u901a\u8fc7Pandas\u7684<code>drop_duplicates<\/code>\u65b9\u6cd5\u3001\u4f7f\u7528\u96c6\u5408\u7684\u7279\u6027\u3001Numpy\u7684unique\u51fd\u6570<\/strong>\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u53bb\u91cd\u5e76\u83b7\u53d6\u67d0\u4e00\u5217\u7684\u6570\u636e\u3002<strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528Pandas\u7684\u65b9\u6cd5\uff1a<\/strong><\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528Pandas\u7684<code>drop_duplicates<\/code>\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u6700\u6d41\u884c\u7684\u7528\u4e8e\u6570\u636e\u5206\u6790\u7684\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u5904\u7406\u6570\u636e\uff0c\u5305\u62ec\u53bb\u91cd\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u548c\u5bfc\u5165Pandas<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5Pandas\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5bfc\u5165Pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u521b\u5efa\u6570\u636e\u6846<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u6846\uff08DataFrame\uff09\uff0c\u8fd9\u901a\u5e38\u662f\u6211\u4eec\u4eceCSV\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Alice&#39;, &#39;Charlie&#39;, &#39;Bob&#39;, &#39;David&#39;],<\/p>\n<p>        &#39;Age&#39;: [25, 30, 25, 35, 30, 40]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u53bb\u91cd\u5e76\u83b7\u53d6\u67d0\u4e00\u5217\u7684\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pandas\u7684<code>drop_duplicates<\/code>\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u53bb\u91cd\u5e76\u63d0\u53d6\u67d0\u4e00\u5217\u7684\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = df[&#39;Name&#39;].drop_duplicates()<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2aSeries\u5bf9\u8c61\uff0c\u5305\u542b\u53bb\u91cd\u540e\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u96c6\u5408\uff08set\uff09<\/h3>\n<\/p>\n<p><p>\u96c6\u5408\u662fPython\u4e2d\u4e00\u4e2a\u5185\u7f6e\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u81ea\u52a8\u53bb\u91cd\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u91cd\u590d\u503c\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">names = [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Alice&#39;, &#39;Charlie&#39;, &#39;Bob&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u96c6\u5408\u53bb\u91cd<\/h4>\n<\/p>\n<p><p>\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u96c6\u5408\uff0c\u7136\u540e\u518d\u8f6c\u6362\u56de\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = list(set(names))<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u867d\u7136\u96c6\u5408\u53ef\u4ee5\u53bb\u91cd\uff0c\u4f46\u5b83\u4e0d\u4f1a\u4fdd\u6301\u539f\u59cb\u6570\u636e\u7684\u987a\u5e8f\u3002\u5982\u679c\u987a\u5e8f\u5f88\u91cd\u8981\uff0c\u8bf7\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Numpy\u7684<code>unique<\/code>\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Numpy\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684Python\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u6570\u503c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u548c\u5bfc\u5165Numpy<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5Numpy\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5bfc\u5165Numpy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u521b\u5efa\u6570\u7ec4<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u91cd\u590d\u503c\u7684Numpy\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">names = np.array([&#39;Alice&#39;, &#39;Bob&#39;, &#39;Alice&#39;, &#39;Charlie&#39;, &#39;Bob&#39;, &#39;David&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u4f7f\u7528<code>unique<\/code>\u51fd\u6570\u53bb\u91cd<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Numpy\u7684<code>unique<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = np.unique(names)<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Numpy\u7684<code>unique<\/code>\u51fd\u6570\u4e0d\u4ec5\u53bb\u91cd\uff0c\u8fd8\u4f1a\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528Pandas\u7684\u8be6\u7ec6\u6b65\u9aa4\u548c\u793a\u4f8b<\/h3>\n<\/p>\n<p><h4>1. \u52a0\u8f7d\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4eceCSV\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u52a0\u8f7d\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4eceCSV\u6587\u4ef6\u4e2d\u52a0\u8f7d\u6570\u636e\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u67e5\u770b\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6570\u636e\u4e4b\u524d\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u5148\u67e5\u770b\u6570\u636e\u7684\u7ed3\u6784\u548c\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(df.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u53bb\u91cd\u5e76\u83b7\u53d6\u67d0\u4e00\u5217\u7684\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u7684\u6570\u636e\u6846\uff0c\u6211\u4eec\u60f3\u53bb\u91cd\u5e76\u83b7\u53d6\u59d3\u540d\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = df[&#39;Name&#39;].drop_duplicates()<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4. \u4fdd\u5b58\u53bb\u91cd\u540e\u7684\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u5c06\u53bb\u91cd\u540e\u7684\u6570\u636e\u4fdd\u5b58\u5230\u65b0\u7684CSV\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names.to_csv(&#39;unique_names.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u96c6\u5408\u7684\u8be6\u7ec6\u6b65\u9aa4\u548c\u793a\u4f8b<\/h3>\n<\/p>\n<p><h4>1. \u4ece\u5217\u8868\u4e2d\u53bb\u91cd<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u91cd\u590d\u503c\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">names = [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Alice&#39;, &#39;Charlie&#39;, &#39;Bob&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u96c6\u5408\u53bb\u91cd<\/h4>\n<\/p>\n<p><p>\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u96c6\u5408\uff0c\u7136\u540e\u518d\u8f6c\u6362\u56de\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = list(set(names))<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Numpy\u7684\u8be6\u7ec6\u6b65\u9aa4\u548c\u793a\u4f8b<\/h3>\n<\/p>\n<p><h4>1. \u521b\u5efa\u6570\u7ec4<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u91cd\u590d\u503c\u7684Numpy\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">names = np.array([&#39;Alice&#39;, &#39;Bob&#39;, &#39;Alice&#39;, &#39;Charlie&#39;, &#39;Bob&#39;, &#39;David&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>unique<\/code>\u51fd\u6570\u53bb\u91cd<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Numpy\u7684<code>unique<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">unique_names = np.unique(names)<\/p>\n<p>print(unique_names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6bd4\u8f83\u4e0d\u540c\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9<\/h3>\n<\/p>\n<p><h4>1. Pandas<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6<\/li>\n<li>\u4fdd\u6301\u6570\u636e\u7684\u987a\u5e8f<\/li>\n<li>\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u5904\u7406\u529f\u80fd<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165Pandas\u5e93<\/li>\n<li>\u5bf9\u4e8e\u975e\u5e38\u7b80\u5355\u7684\u4efb\u52a1\u53ef\u80fd\u6709\u4e9b\u8fc7\u5ea6<\/li>\n<\/ul>\n<p><h4>2. \u96c6\u5408<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5185\u7f6e\u6570\u636e\u7ed3\u6784\uff0c\u65e0\u9700\u5b89\u88c5\u989d\u5916\u7684\u5e93<\/li>\n<li>\u4ee3\u7801\u7b80\u6d01<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4e0d\u4fdd\u6301\u6570\u636e\u7684\u987a\u5e8f<\/li>\n<li>\u529f\u80fd\u76f8\u5bf9\u6709\u9650<\/li>\n<\/ul>\n<p><h4>3. Numpy<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9002\u5408\u6570\u503c\u8ba1\u7b97\u548c\u5904\u7406\u5927\u578b\u6570\u7ec4<\/li>\n<li>\u4fdd\u6301\u6570\u636e\u7684\u987a\u5e8f\uff08\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff09<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165Numpy\u5e93<\/li>\n<li>\u5bf9\u4e8e\u7b80\u5355\u4efb\u52a1\u53ef\u80fd\u6709\u4e9b\u8fc7\u5ea6<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u53bb\u91cd\u5e76\u83b7\u53d6\u6570\u636e\u7684\u67d0\u4e00\u5217\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5176\u4e2d<strong>Pandas<\/strong> \u662f\u6700\u5e38\u7528\u548c\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u5c24\u5176\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<strong>\u96c6\u5408<\/strong> \u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u4f46\u5b83\u4e0d\u4fdd\u6301\u6570\u636e\u7684\u987a\u5e8f\u3002<strong>Numpy<\/strong> \u9002\u5408\u6570\u503c\u8ba1\u7b97\u548c\u5904\u7406\u5927\u578b\u6570\u7ec4\uff0c\u4f46\u5bf9\u4e8e\u7b80\u5355\u4efb\u52a1\u53ef\u80fd\u6709\u4e9b\u8fc7\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u6570\u636e\u96c6\u7684\u89c4\u6a21\u3002\u5982\u679c\u4f60\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u5e76\u4e14\u9700\u8981\u4fdd\u7559\u6570\u636e\u7684\u987a\u5e8f\uff0c<strong>Pandas\u662f\u6700\u4f73\u9009\u62e9<\/strong>\u3002\u5982\u679c\u4f60\u53ea\u9700\u8981\u4e00\u4e2a\u7b80\u5355\u7684\u53bb\u91cd\u64cd\u4f5c\uff0c\u5e76\u4e14\u4e0d\u5728\u610f\u987a\u5e8f\uff0c<strong>\u96c6\u5408\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9<\/strong>\u3002\u5bf9\u4e8e\u6d89\u53ca\u5927\u91cf\u6570\u503c\u8ba1\u7b97\u7684\u4efb\u52a1\uff0c<strong>Numpy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177<\/strong>\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u7406\u89e3\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\uff0c\u5e76\u6839\u636e\u5177\u4f53\u60c5\u51b5\u505a\u51fa\u9009\u62e9\uff0c\u662f\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4e2d\u7684\u91cd\u8981\u6280\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9ad8\u6548\u53bb\u91cd\u67d0\u4e00\u5217\u7684\u6570\u636e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u5229\u7528Pandas\u5e93\u7684<code>drop_duplicates()<\/code>\u65b9\u6cd5\u8f7b\u677e\u5b9e\u73b0\u53bb\u91cd\u3002\u9996\u5148\uff0c\u5c06\u6570\u636e\u8bfb\u5165\u4e3aDataFrame\uff0c\u7136\u540e\u9009\u62e9\u9700\u8981\u53bb\u91cd\u7684\u5217\uff0c\u6700\u540e\u8c03\u7528<code>drop_duplicates()<\/code>\u51fd\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u4fdd\u6301\u5176\u4ed6\u5217\u7684\u6570\u636e\u4e0d\u53d8\uff0c\u540c\u65f6\u53ea\u5bf9\u6307\u5b9a\u5217\u8fdb\u884c\u53bb\u91cd\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u9664\u4e86Pandas\uff0c\u8fd8\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u53bb\u91cd\u6570\u636e\u7684\u67d0\u4e00\u5217\uff1f<\/strong><br \/>\u9664\u4e86\u4f7f\u7528Pandas\uff0cPython\u7684\u539f\u751f\u6570\u636e\u7ed3\u6784\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u53bb\u91cd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u96c6\u5408\uff08set\uff09\u6765\u53bb\u91cd\u5217\u8868\u4e2d\u7684\u5143\u7d20\uff0c\u6216\u4f7f\u7528\u5b57\u5178\u7684\u952e\u6765\u81ea\u52a8\u53bb\u91cd\u3002\u5bf9\u4e8e\u8f83\u5c0f\u7684\u6570\u636e\u96c6\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u5f88\u6709\u6548\uff0c\u4f46\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0cPandas\u4f1a\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u66f4\u591a\u7684\u529f\u80fd\u3002<\/p>\n<p><strong>\u5728\u53bb\u91cd\u67d0\u4e00\u5217\u65f6\uff0c\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u53bb\u91cd\u64cd\u4f5c\u65f6\uff0c\u7f3a\u5931\u503c\uff08NaN\uff09\u4f1a\u88ab\u89c6\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u503c\u3002\u5982\u679c\u5e0c\u671b\u5728\u53bb\u91cd\u8fc7\u7a0b\u4e2d\u5ffd\u7565\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u5728\u4f7f\u7528<code>drop_duplicates()<\/code>\u65f6\u8bbe\u7f6e<code>keep=&#39;first&#39;<\/code>\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u7559\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684\u975e\u7f3a\u5931\u503c\uff0c\u5e76\u53bb\u9664\u540e\u7eed\u7684\u91cd\u590d\u9879\u3002\u5bf9\u4e8e\u7f3a\u5931\u503c\u7684\u5904\u7406\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u4fdd\u7559\u6216\u5220\u9664\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u53bb\u91cd\u53d6\u6570\u636e\u7684\u67d0\u4e00\u5217\u6709\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528Pandas\u3001\u4f7f\u7528\u96c6\u5408\u3001\u4f7f\u7528Numpy\u7b49\u3002\u5176\u4e2d\uff0cPan [&hellip;]","protected":false},"author":3,"featured_media":1141887,"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\/1141881"}],"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=1141881"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1141881\/revisions"}],"predecessor-version":[{"id":1141888,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1141881\/revisions\/1141888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1141887"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1141881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1141881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1141881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}