{"id":1144225,"date":"2025-01-08T22:57:44","date_gmt":"2025-01-08T14:57:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1144225.html"},"modified":"2025-01-08T22:57:48","modified_gmt":"2025-01-08T14:57:48","slug":"python%e5%a6%82%e4%bd%95%e5%89%94%e9%99%a4%e4%b8%80%e4%b8%aa%e5%ad%97%e6%ae%b5%e7%9a%84%e7%89%b9%e5%ae%9a%e5%8f%96%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1144225.html","title":{"rendered":"python\u5982\u4f55\u5254\u9664\u4e00\u4e2a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181428\/125e9422-a5cc-4ab9-b7b5-aea6a3797af6.webp\" alt=\"python\u5982\u4f55\u5254\u9664\u4e00\u4e2a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5254\u9664\u4e00\u4e2a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u8fc7\u6ee4\u51fd\u6570\u7b49\u3002<\/strong> \u4ee5\u4e0b\u662f\u8be6\u7ec6\u63cf\u8ff0\u4e00\u79cd\u5e38\u7528\u65b9\u6cd5\u2014\u2014\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\uff0c\u901a\u8fc7\u904d\u5386\u548c\u6761\u4ef6\u5224\u65ad\u6765\u5254\u9664\u7279\u5b9a\u53d6\u503c\u3002<strong>\u8fd9\u4e2a\u65b9\u6cd5\u7b80\u5355\u6613\u61c2\uff0c\u9002\u5408\u521d\u5b66\u8005\u548c\u9700\u8981\u5feb\u901f\u5904\u7406\u5c0f\u89c4\u6a21\u6570\u636e\u7684\u573a\u666f\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u5178\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u5b57\u5178\u8868\u793a\u4e00\u6761\u8bb0\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u591a\u4e2a\u5b57\u6bb5\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u4ece\u8fd9\u4e9b\u8bb0\u5f55\u4e2d\u5254\u9664\u5b57\u6bb5\u4e2d\u5305\u542b\u7279\u5b9a\u53d6\u503c\u7684\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u5254\u9664\u7279\u5b9a\u53d6\u503c\u7684\u57fa\u672c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u904d\u5386\u5217\u8868\u4e2d\u6bcf\u6761\u8bb0\u5f55\uff1b<\/li>\n<li>\u68c0\u67e5\u8bb0\u5f55\u4e2d\u7279\u5b9a\u5b57\u6bb5\u7684\u503c\u662f\u5426\u4e3a\u9700\u8981\u5254\u9664\u7684\u503c\uff1b<\/li>\n<li>\u5982\u679c\u4e0d\u662f\uff0c\u5219\u5c06\u8bb0\u5f55\u4fdd\u7559\u4e0b\u6765\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u6570\u636e<\/p>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Los Angeles&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;David&quot;, &quot;age&quot;: 40, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>]<\/p>\n<h2><strong>\u8981\u5254\u9664\u7684\u57ce\u5e02<\/strong><\/h2>\n<p>city_to_remove = &quot;New York&quot;<\/p>\n<h2><strong>\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/strong><\/h2>\n<p>filtered_data = [record for record in data if record[&quot;city&quot;] != city_to_remove]<\/p>\n<p>print(filtered_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u5217\u8868\u63a8\u5bfc\u5f0f\uff08List Comprehension\uff09\u6765\u904d\u5386\u6bcf\u6761\u8bb0\u5f55\uff0c\u5e76\u68c0\u67e5\u5b57\u6bb5<code>city<\/code>\u7684\u503c\u662f\u5426\u4e3a<code>&quot;New York&quot;<\/code>\u3002\u5982\u679c\u4e0d\u662f\uff0c\u5219\u5c06\u8bb0\u5f55\u4fdd\u7559\u5728\u65b0\u7684\u5217\u8868<code>filtered_data<\/code>\u4e2d\u3002\u6700\u7ec8\u8f93\u51fa\u7684<code>filtered_data<\/code>\u5217\u8868\u4e0d\u5305\u542b<code>city<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;New York&quot;<\/code>\u7684\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Pandas\u5e93\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u5927\u89c4\u6a21\u7684\u6570\u636e\u548c\u66f4\u590d\u6742\u7684\u5904\u7406\u9700\u6c42\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u3002Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u64cd\u4f5c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5254\u9664\u7279\u5b9a\u53d6\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Los Angeles&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;David&quot;, &quot;age&quot;: 40, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>]<\/p>\n<h2><strong>\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u8981\u5254\u9664\u7684\u57ce\u5e02<\/strong><\/h2>\n<p>city_to_remove = &quot;New York&quot;<\/p>\n<h2><strong>\u4f7f\u7528Pandas\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/strong><\/h2>\n<p>filtered_df = df[df[&quot;city&quot;] != city_to_remove]<\/p>\n<p>print(filtered_df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u793a\u4f8b\u6570\u636e\u8f6c\u6362\u4e3a\u4e00\u4e2aPandas DataFrame\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\uff08Boolean Indexing\uff09\u6765\u8fc7\u6ee4\u6389<code>city<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;New York&quot;<\/code>\u7684\u8bb0\u5f55\u3002\u6700\u7ec8\u8f93\u51fa\u7684<code>filtered_df<\/code> DataFrame\u4e0d\u5305\u542b<code>city<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;New York&quot;<\/code>\u7684\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u8fc7\u6ee4\u51fd\u6570\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/h3>\n<\/p>\n<p><p>Python\u5185\u7f6e\u7684<code>filter<\/code>\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5254\u9664\u7279\u5b9a\u53d6\u503c\u3002<code>filter<\/code>\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u51fd\u6570\u548c\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u5176\u4e2d\u5305\u542b\u6240\u6709\u4f7f\u51fd\u6570\u8fd4\u56de<code>True<\/code>\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u6570\u636e<\/p>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Los Angeles&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;David&quot;, &quot;age&quot;: 40, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>]<\/p>\n<h2><strong>\u8981\u5254\u9664\u7684\u57ce\u5e02<\/strong><\/h2>\n<p>city_to_remove = &quot;New York&quot;<\/p>\n<h2><strong>\u5b9a\u4e49\u8fc7\u6ee4\u51fd\u6570<\/strong><\/h2>\n<p>def filter_city(record):<\/p>\n<p>    return record[&quot;city&quot;] != city_to_remove<\/p>\n<h2><strong>\u4f7f\u7528\u8fc7\u6ee4\u51fd\u6570\u5254\u9664\u7279\u5b9a\u53d6\u503c<\/strong><\/h2>\n<p>filtered_data = list(filter(filter_city, data))<\/p>\n<p>print(filtered_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u8fc7\u6ee4\u51fd\u6570<code>filter_city<\/code>\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u6761\u8bb0\u5f55\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de<code>True<\/code>\u6216<code>False<\/code>\uff0c\u6839\u636e<code>city<\/code>\u5b57\u6bb5\u7684\u503c\u662f\u5426\u4e3a\u9700\u8981\u5254\u9664\u7684\u503c\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>filter<\/code>\u51fd\u6570\u6765\u8fc7\u6ee4\u6570\u636e\uff0c\u5e76\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u66f4\u590d\u6742\u7684\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5904\u7406\u66f4\u590d\u6742\u7684\u573a\u666f\uff0c\u4f8b\u5982\u5254\u9664\u591a\u4e2a\u5b57\u6bb5\u4e2d\u7684\u7279\u5b9a\u53d6\u503c\uff0c\u6216\u8005\u57fa\u4e8e\u591a\u4e2a\u6761\u4ef6\u8fdb\u884c\u8fc7\u6ee4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5904\u7406\u66f4\u590d\u6742\u573a\u666f\u7684\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u5254\u9664\u591a\u4e2a\u5b57\u6bb5\u4e2d\u7684\u7279\u5b9a\u53d6\u503c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u6570\u636e<\/p>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;, &quot;status&quot;: &quot;single&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Los Angeles&quot;, &quot;status&quot;: &quot;married&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;New York&quot;, &quot;status&quot;: &quot;single&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;David&quot;, &quot;age&quot;: 40, &quot;city&quot;: &quot;Chicago&quot;, &quot;status&quot;: &quot;married&quot;},<\/p>\n<p>]<\/p>\n<h2><strong>\u8981\u5254\u9664\u7684\u57ce\u5e02\u548c\u72b6\u6001<\/strong><\/h2>\n<p>city_to_remove = &quot;New York&quot;<\/p>\n<p>status_to_remove = &quot;single&quot;<\/p>\n<h2><strong>\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u5254\u9664\u591a\u4e2a\u5b57\u6bb5\u4e2d\u7684\u7279\u5b9a\u53d6\u503c<\/strong><\/h2>\n<p>filtered_data = [<\/p>\n<p>    record for record in data<\/p>\n<p>    if record[&quot;city&quot;] != city_to_remove and record[&quot;status&quot;] != status_to_remove<\/p>\n<p>]<\/p>\n<p>print(filtered_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u540c\u65f6\u5254\u9664\u4e86<code>city<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;New York&quot;<\/code>\u548c<code>status<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;single&quot;<\/code>\u7684\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h4>2. \u57fa\u4e8e\u591a\u4e2a\u6761\u4ef6\u8fdb\u884c\u8fc7\u6ee4<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u6570\u636e<\/p>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;, &quot;status&quot;: &quot;single&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Los Angeles&quot;, &quot;status&quot;: &quot;married&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;New York&quot;, &quot;status&quot;: &quot;single&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;David&quot;, &quot;age&quot;: 40, &quot;city&quot;: &quot;Chicago&quot;, &quot;status&quot;: &quot;married&quot;},<\/p>\n<p>]<\/p>\n<h2><strong>\u8981\u5254\u9664\u7684\u57ce\u5e02\u548c\u72b6\u6001<\/strong><\/h2>\n<p>city_to_remove = &quot;New York&quot;<\/p>\n<p>min_age = 30<\/p>\n<h2><strong>\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u57fa\u4e8e\u591a\u4e2a\u6761\u4ef6\u8fdb\u884c\u8fc7\u6ee4<\/strong><\/h2>\n<p>filtered_data = [<\/p>\n<p>    record for record in data<\/p>\n<p>    if record[&quot;city&quot;] != city_to_remove and record[&quot;age&quot;] &gt;= min_age<\/p>\n<p>]<\/p>\n<p>print(filtered_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5254\u9664\u4e86<code>city<\/code>\u5b57\u6bb5\u503c\u4e3a<code>&quot;New York&quot;<\/code>\u4e14<code>age<\/code>\u5b57\u6bb5\u503c\u5c0f\u4e8e<code>30<\/code>\u7684\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5254\u9664\u4e00\u4e2a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u8fc7\u6ee4\u51fd\u6570\u4ee5\u53caPandas\u5e93\u3002<strong>\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\u548c\u9700\u6c42\u3002<\/strong>\u5bf9\u4e8e\u7b80\u5355\u7684\u8fc7\u6ee4\u9700\u6c42\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u548c\u5217\u8868\u63a8\u5bfc\u5f0f\uff1b\u5bf9\u4e8e\u66f4\u590d\u6742\u548c\u5927\u89c4\u6a21\u7684\u6570\u636e\u5904\u7406\u9700\u6c42\uff0c\u5efa\u8bae\u4f7f\u7528Pandas\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u91c7\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u5173\u952e\u5728\u4e8e\u7406\u89e3\u6570\u636e\u7ed3\u6784\u548c\u8fc7\u6ee4\u6761\u4ef6\uff0c\u5e76\u9009\u62e9\u6700\u9002\u5408\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u6765\u9ad8\u6548\u5730\u5904\u7406\u6570\u636e\u3002<strong>\u901a\u8fc7\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u6280\u672f\uff0c\u80fd\u591f\u5728\u6570\u636e\u5904\u7406\u4e2d\u5254\u9664\u4e0d\u9700\u8981\u7684\u5b57\u6bb5\u503c\uff0c\u63d0\u9ad8\u6570\u636e\u8d28\u91cf\u548c\u5206\u6790\u6548\u7387\u3002<\/strong><\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5220\u9664\u7279\u5b9a\u5b57\u6bb5\u7684\u7279\u5b9a\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u6765\u8f7b\u677e\u5730\u5254\u9664\u7279\u5b9a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c\u3002\u901a\u8fc7\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684DataFrame\uff0c\u5176\u4e2d\u4e0d\u5305\u542b\u60a8\u60f3\u8981\u5254\u9664\u7684\u503c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u4ece\u67d0\u5217\u4e2d\u5220\u9664\u6240\u6709\u503c\u4e3a\u201c\u65e0\u6548\u201d\u7684\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\n# \u521b\u5efa\u793a\u4f8bDataFrame\ndata = {&#39;\u5b57\u6bb5\u540d&#39;: [&#39;\u6709\u6548&#39;, &#39;\u65e0\u6548&#39;, &#39;\u6709\u6548&#39;, &#39;\u65e0\u6548&#39;]}\ndf = pd.DataFrame(data)\n\n# \u5254\u9664\u7279\u5b9a\u53d6\u503c\ndf_filtered = df[df[&#39;\u5b57\u6bb5\u540d&#39;] != &#39;\u65e0\u6548&#39;]\nprint(df_filtered)\n<\/code><\/pre>\n<p><strong>\u5254\u9664\u7279\u5b9a\u503c\u540e\uff0c\u5982\u4f55\u4fdd\u5b58\u6216\u8f93\u51fa\u66f4\u65b0\u540e\u7684\u6570\u636e\uff1f<\/strong><br \/>\u4f7f\u7528Pandas\u5904\u7406\u6570\u636e\u65f6\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u66f4\u65b0\u540e\u7684DataFrame\u4fdd\u5b58\u4e3a\u65b0\u7684CSV\u6587\u4ef6\u6216Excel\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528<code>to_csv()<\/code>\u6216<code>to_excel()<\/code>\u65b9\u6cd5\u8fdb\u884c\u4fdd\u5b58\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5c06\u66f4\u65b0\u540e\u7684DataFrame\u4fdd\u5b58\u4e3aCSV\u6587\u4ef6\ndf_filtered.to_csv(&#39;\u66f4\u65b0\u540e\u7684\u6570\u636e.csv&#39;, index=False)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u5254\u9664\u7279\u5b9a\u53d6\u503c\u540e\u7684\u6570\u636e\u80fd\u591f\u88ab\u6709\u6548\u4fdd\u5b58\u4ee5\u4fbf\u540e\u7eed\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5728\u5254\u9664\u5b57\u6bb5\u7279\u5b9a\u53d6\u503c\u65f6\uff0c\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u6570\u636e\u6e05\u6d17\u8fc7\u7a0b\u4e2d\uff0c\u5904\u7406\u7f3a\u5931\u503c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u60a8\u53ef\u4ee5\u5728\u5254\u9664\u7279\u5b9a\u53d6\u503c\u4e4b\u524d\uff0c\u5148\u4f7f\u7528<code>dropna()<\/code>\u65b9\u6cd5\u5220\u9664\u7f3a\u5931\u503c\uff0c\u6216\u8005\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u8fdb\u884c\u586b\u5145\u3002\u8fd9\u6837\uff0c\u53ef\u4ee5\u786e\u4fdd\u5728\u6700\u7ec8\u6570\u636e\u96c6\u4e2d\u6ca1\u6709\u7f3a\u5931\u503c\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u8d28\u91cf\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5728\u5254\u9664\u7279\u5b9a\u53d6\u503c\u4e4b\u524d\uff0c\u5904\u7406\u7f3a\u5931\u503c\ndf = df.dropna()  # \u5220\u9664\u7f3a\u5931\u503c\ndf_filtered = df[df[&#39;\u5b57\u6bb5\u540d&#39;] != &#39;\u65e0\u6548&#39;]  # \u5254\u9664\u7279\u5b9a\u53d6\u503c\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6570\u636e\u5e76\u63d0\u5347\u5176\u51c6\u786e\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5254\u9664\u4e00\u4e2a\u5b57\u6bb5\u7684\u7279\u5b9a\u53d6\u503c\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u8fc7\u6ee4\u51fd\u6570\u7b49\u3002 \u4ee5\u4e0b\u662f\u8be6\u7ec6\u63cf\u8ff0\u4e00\u79cd [&hellip;]","protected":false},"author":3,"featured_media":1144233,"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\/1144225"}],"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=1144225"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144225\/revisions"}],"predecessor-version":[{"id":1144237,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144225\/revisions\/1144237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1144233"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1144225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1144225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1144225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}