{"id":1155095,"date":"2025-01-13T17:59:07","date_gmt":"2025-01-13T09:59:07","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155095.html"},"modified":"2025-01-13T17:59:10","modified_gmt":"2025-01-13T09:59:10","slug":"python%e5%a6%82%e4%bd%95drop%e6%9f%90%e4%ba%9b%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1155095.html","title":{"rendered":"python\u5982\u4f55drop\u67d0\u4e9b\u884c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25184544\/b55ef094-91e4-4f87-bf7b-5df849181705.webp\" alt=\"python\u5982\u4f55drop\u67d0\u4e9b\u884c\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d:<\/p>\n<p><strong>\u5728Python\u4e2d\uff0c\u4f7f\u7528pandas\u5e93\u3001drop\u51fd\u6570\u3001\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u3001\u5220\u9664\u67d0\u4e9b\u884c\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528pandas\u5e93\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\u3002pandas\u5e93\u4e2d\u7684drop\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5220\u9664\u7b26\u5408\u7279\u5b9a\u6761\u4ef6\u7684\u884c\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u884c\u7d22\u5f15\u3001\u7279\u5b9a\u5217\u7684\u503c\u3001\u5e03\u5c14\u7d22\u5f15\u7b49\u6761\u4ef6\u6765\u5220\u9664\u884c\u3002\u5177\u4f53\u64cd\u4f5c\u5305\u62ec\u5bfc\u5165pandas\u5e93\u3001\u521b\u5efa\u6216\u8bfb\u53d6DataFrame\u3001\u4f7f\u7528drop\u51fd\u6570\u5220\u9664\u884c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pandas\u5e93\u6765\u5220\u9664\u67d0\u4e9b\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528pandas\u5e93\u5220\u9664\u884c<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0cpandas\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u5e93\u3002pandas\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u5305\u62ec\u5220\u9664\u884c\u7684\u529f\u80fd\u3002\u901a\u8fc7\u5bfc\u5165pandas\u5e93\u5e76\u521b\u5efa\u6216\u8bfb\u53d6DataFrame\uff0c\u53ef\u4ee5\u4f7f\u7528drop\u51fd\u6570\u5220\u9664\u7b26\u5408\u6761\u4ef6\u7684\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u6839\u636e\u884c\u7d22\u5f15\u5220\u9664\u884c<\/strong><\/h2>\n<p>df = df.drop([0, 2])<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u6839\u636e\u7279\u5b9a\u5217\u7684\u503c\u5220\u9664\u884c<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u53ef\u80fd\u9700\u8981\u6839\u636e\u7279\u5b9a\u5217\u7684\u503c\u6765\u5220\u9664\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u5e03\u5c14\u7d22\u5f15\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u7b5b\u9009\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u5217B\u4e2d\u503c\u4e3a&#39;a&#39;\u7684\u884c<\/strong><\/h2>\n<p>df = df[df[&#39;B&#39;] != &#39;a&#39;]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\u5220\u9664\u884c<\/p>\n<\/p>\n<p><p>\u5e03\u5c14\u7d22\u5f15\u662f\u4e00\u79cd\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u7b5b\u9009\u6570\u636e\u7684\u65b9\u6cd5\u3002\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5e03\u5c14\u7d22\u5f15\u6765\u5220\u9664\u7b26\u5408\u6761\u4ef6\u7684\u884c\u3002\u5e03\u5c14\u7d22\u5f15\u662f\u4e00\u4e2a\u5305\u542bTrue\u6216False\u503c\u7684\u6570\u7ec4\uff0c\u6839\u636e\u8fd9\u4e9b\u503c\u7b5b\u9009\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u521b\u5efa\u5e03\u5c14\u7d22\u5f15<\/strong><\/h2>\n<p>bool_index = df[&#39;A&#39;] &gt; 2<\/p>\n<h2><strong>\u5220\u9664\u7b26\u5408\u5e03\u5c14\u7d22\u5f15\u6761\u4ef6\u7684\u884c<\/strong><\/h2>\n<p>df = df[bool_index]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u5220\u9664\u884c<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u6765\u5220\u9664\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\uff08\u5982&amp;\u3001|\uff09\u6765\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\u3002\u8fd9\u6837\u53ef\u4ee5\u66f4\u52a0\u7075\u6d3b\u5730\u5220\u9664\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u5217A\u4e2d\u503c\u5927\u4e8e2\u4e14\u5217B\u4e2d\u503c\u4e3a&#39;c&#39;\u7684\u884c<\/strong><\/h2>\n<p>df = df[(df[&#39;A&#39;] &lt;= 2) | (df[&#39;B&#39;] != &#39;c&#39;)]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5220\u9664\u91cd\u590d\u884c<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5904\u7406\u4e2d\uff0c\u5904\u7406\u91cd\u590d\u6570\u636e\u662f\u5e38\u89c1\u7684\u4efb\u52a1\u3002pandas\u5e93\u63d0\u4f9b\u4e86drop_duplicates\u51fd\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u5220\u9664\u91cd\u590d\u884c\u3002\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u5217\u6216\u6574\u4e2aDataFrame\u6765\u5220\u9664\u91cd\u590d\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 2, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;b&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>df = df.drop_duplicates()<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5220\u9664\u7a7a\u503c\u884c<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u6e05\u6d17\u8fc7\u7a0b\u4e2d\uff0c\u5904\u7406\u7a7a\u503c\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4efb\u52a1\u3002pandas\u5e93\u63d0\u4f9b\u4e86dropna\u51fd\u6570\uff0c\u53ef\u4ee5\u5220\u9664\u5305\u542b\u7a7a\u503c\u7684\u884c\u3002\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u5217\u6216\u6574\u4e2aDataFrame\u6765\u5220\u9664\u7a7a\u503c\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, None, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, None, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u5305\u542b\u7a7a\u503c\u7684\u884c<\/strong><\/h2>\n<p>df = df.dropna()<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528iloc\u5220\u9664\u884c<\/p>\n<\/p>\n<p><p>iloc\u662fpandas\u5e93\u4e2d\u7684\u4e00\u79cd\u57fa\u4e8e\u4f4d\u7f6e\u7684\u7d22\u5f15\u65b9\u6cd5\u3002\u53ef\u4ee5\u4f7f\u7528iloc\u6765\u5220\u9664\u6307\u5b9a\u4f4d\u7f6e\u7684\u884c\u3002\u901a\u8fc7\u4f20\u9012\u884c\u7684\u4f4d\u7f6e\u7d22\u5f15\uff0c\u53ef\u4ee5\u5220\u9664\u7279\u5b9a\u4f4d\u7f6e\u7684\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u7b2c1\u548c\u7b2c3\u884c<\/strong><\/h2>\n<p>df = df.drop(df.index[[0, 2]])<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516b\u3001\u5220\u9664\u67d0\u4e9b\u884c\u5e76\u91cd\u7f6e\u7d22\u5f15<\/p>\n<\/p>\n<p><p>\u5220\u9664\u884c\u540e\uff0c\u7d22\u5f15\u53ef\u80fd\u4f1a\u53d8\u5f97\u4e0d\u8fde\u7eed\u3002\u53ef\u4ee5\u4f7f\u7528reset_index\u51fd\u6570\u6765\u91cd\u7f6e\u7d22\u5f15\uff0c\u4f7f\u7d22\u5f15\u91cd\u65b0\u53d8\u5f97\u8fde\u7eed\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u7b2c1\u548c\u7b2c3\u884c<\/strong><\/h2>\n<p>df = df.drop(df.index[[0, 2]])<\/p>\n<h2><strong>\u91cd\u7f6e\u7d22\u5f15<\/strong><\/h2>\n<p>df = df.reset_index(drop=True)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e5d\u3001\u5220\u9664\u884c\u5e76\u4fdd\u5b58\u5230\u65b0\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u5904\u7406\u540e\u7684\u6570\u636e\u4fdd\u5b58\u5230\u65b0\u7684\u6587\u4ef6\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528pandas\u5e93\u63d0\u4f9b\u7684to_csv\u6216to_excel\u51fd\u6570\u5c06\u5904\u7406\u540e\u7684\u6570\u636e\u4fdd\u5b58\u5230CSV\u6216Excel\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;B&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5220\u9664\u7b2c1\u548c\u7b2c3\u884c<\/strong><\/h2>\n<p>df = df.drop(df.index[[0, 2]])<\/p>\n<h2><strong>\u4fdd\u5b58\u5230\u65b0\u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;processed_data.csv&#39;, index=False)<\/p>\n<p>print(&#39;Data saved to processed_data.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5341\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cpandas\u5e93\u63d0\u4f9b\u4e86\u591a\u79cd\u5220\u9664\u884c\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u6839\u636e\u884c\u7d22\u5f15\u3001\u7279\u5b9a\u5217\u7684\u503c\u3001\u5e03\u5c14\u7d22\u5f15\u3001\u591a\u4e2a\u6761\u4ef6\u3001\u5220\u9664\u91cd\u590d\u884c\u3001\u5220\u9664\u7a7a\u503c\u884c\u3001\u4f7f\u7528iloc\u5220\u9664\u884c\u3001\u5220\u9664\u884c\u5e76\u91cd\u7f6e\u7d22\u5f15\u3001\u5220\u9664\u884c\u5e76\u4fdd\u5b58\u5230\u65b0\u6587\u4ef6\u7b49\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5728\u6570\u636e\u6e05\u6d17\u548c\u5904\u7406\u8fc7\u7a0b\u4e2d\u975e\u5e38\u5b9e\u7528\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u5220\u9664\u67d0\u4e9b\u884c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5220\u9664\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u884c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u7684<code>drop<\/code>\u65b9\u6cd5\u6765\u5220\u9664\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u884c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u67d0\u4e00\u5217\u7684\u503c\u6765\u7b5b\u9009\u51fa\u9700\u8981\u5220\u9664\u7684\u884c\u3002\u9996\u5148\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5e03\u5c14\u7d22\u5f15\u627e\u5230\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u884c\uff0c\u7136\u540e\u4f7f\u7528<code>drop<\/code>\u65b9\u6cd5\u8fdb\u884c\u5220\u9664\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\n# \u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u636e\u6846\ndf = pd.DataFrame({&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]})\n\n# \u5220\u9664\u5217&#39;A&#39;\u4e2d\u7b49\u4e8e2\u7684\u884c\ndf = df[df[&#39;A&#39;] != 2]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7075\u6d3b\u5730\u6839\u636e\u6761\u4ef6\u5220\u9664\u884c\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u6570\u636e\u6e05\u6d17\u573a\u666f\u3002<\/p>\n<p><strong>\u5728Pandas\u4e2d\uff0c\u5982\u4f55\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u5220\u9664\u884c\uff1f<\/strong><br \/>\u4f7f\u7528Pandas\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u903b\u8f91\u8fd0\u7b97\u7b26\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\u6765\u5220\u9664\u884c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>&amp;<\/code>\uff08\u4e0e\uff09\u6216<code>|<\/code>\uff08\u6216\uff09\u8fd0\u7b97\u7b26\u6765\u6307\u5b9a\u591a\u4e2a\u6761\u4ef6\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5220\u9664\u540c\u65f6\u6ee1\u8db3\u6761\u4ef6A&gt;1\u548cB&lt;6\u7684\u884c\ndf = df[~((df[&#39;A&#39;] &gt; 1) &amp; (df[&#39;B&#39;] &lt; 6))]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u8ba9\u60a8\u53ef\u4ee5\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u5220\u9664\u54ea\u4e9b\u884c\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u6839\u636e\u884c\u7d22\u5f15\u76f4\u63a5\u5220\u9664\u884c\uff1f<\/strong><br \/>\u786e\u5b9e\u53ef\u4ee5\uff0cPandas\u4e2d\u7684<code>drop<\/code>\u65b9\u6cd5\u5141\u8bb8\u60a8\u6839\u636e\u884c\u7d22\u5f15\u76f4\u63a5\u5220\u9664\u884c\u3002\u60a8\u53ea\u9700\u5c06\u8981\u5220\u9664\u7684\u7d22\u5f15\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9<code>drop<\/code>\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5220\u9664\u7d22\u5f15\u4e3a0\u7684\u884c\ndf = df.drop(index=0)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u60a8\u5df2\u77e5\u5177\u4f53\u7d22\u5f15\u7684\u60c5\u51b5\uff0c\u7b80\u5316\u4e86\u64cd\u4f5c\u6b65\u9aa4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d: \u5728Python\u4e2d\uff0c\u4f7f\u7528pandas\u5e93\u3001drop\u51fd\u6570\u3001\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u3001\u5220\u9664\u67d0\u4e9b\u884c\u3002 \u5176\u4e2d\uff0c\u4f7f\u7528pand [&hellip;]","protected":false},"author":3,"featured_media":1155099,"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\/1155095"}],"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=1155095"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155095\/revisions"}],"predecessor-version":[{"id":1155104,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155095\/revisions\/1155104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1155099"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1155095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1155095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1155095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}