{"id":964775,"date":"2024-12-27T04:31:39","date_gmt":"2024-12-26T20:31:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/964775.html"},"modified":"2024-12-27T04:31:40","modified_gmt":"2024-12-26T20:31:40","slug":"python%e5%a6%82%e4%bd%95%e9%80%89%e5%8f%96%e4%b8%aa%e5%88%ab%e5%88%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/964775.html","title":{"rendered":"python\u5982\u4f55\u9009\u53d6\u4e2a\u522b\u5217"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181411\/e011df09-0770-4b20-9b56-27fc74495967.webp\" alt=\"python\u5982\u4f55\u9009\u53d6\u4e2a\u522b\u5217\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u9009\u53d6\u6570\u636e\u6846\u7684\u4e2a\u522b\u5217\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u5c24\u5176\u662f\u5728\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u65f6\u3002<strong>\u4f7f\u7528Pandas\u5e93\u3001\u901a\u8fc7\u5217\u540d\u6216\u4f4d\u7f6e\u7d22\u5f15\u3001\u5229\u7528\u5e03\u5c14\u7d22\u5f15<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u4efb\u52a1\u7684\u4e3b\u8981\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff0c\u5e76\u63d0\u4f9b\u5168\u9762\u7684\u6307\u5bfc\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528Pandas\u5e93<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u3002\u901a\u8fc7Pandas\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u4ece\u6570\u636e\u6846\u4e2d\u9009\u53d6\u4e2a\u522b\u5217\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u5217\u540d\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u5f53\u4f60\u77e5\u9053\u9700\u8981\u9009\u62e9\u7684\u5217\u7684\u540d\u79f0\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5217\u540d\u6765\u63d0\u53d6\u8fd9\u4e9b\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35],<\/p>\n<p>    &#39;City&#39;: [&#39;New York&#39;, &#39;Los Angeles&#39;, &#39;Chicago&#39;]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u9009\u62e9\u5355\u5217<\/strong><\/h2>\n<p>age_column = df[&#39;Age&#39;]<\/p>\n<h2><strong>\u9009\u62e9\u591a\u5217<\/strong><\/h2>\n<p>name_city_columns = df[[&#39;Name&#39;, &#39;City&#39;]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u793a\u4f8b\u6570\u636e\u6846<code>df<\/code>\u3002\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u5217\u540d\u9009\u62e9\u4e86\u5355\u5217<code>Age<\/code>\u548c\u591a\u5217<code>Name<\/code>\u548c<code>City<\/code>\u3002<strong>\u4f7f\u7528\u5217\u540d\u9009\u62e9\u5217\u662f\u6700\u76f4\u63a5\u548c\u5e38\u7528\u7684\u65b9\u6cd5<\/strong>\uff0c\u5c24\u5176\u5f53\u4f60\u5bf9\u6570\u636e\u7ed3\u6784\u6bd4\u8f83\u719f\u6089\u65f6\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u4f4d\u7f6e\u7d22\u5f15\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4e0d\u77e5\u9053\u5217\u540d\u6216\u8005\u66f4\u559c\u6b22\u4f7f\u7528\u4f4d\u7f6e\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528<code>iloc<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u7b2c\u4e8c\u5217\uff08\u4ece0\u5f00\u59cb\u7d22\u5f15\uff09<\/p>\n<p>age_column_by_index = df.iloc[:, 1]<\/p>\n<h2><strong>\u9009\u62e9\u7b2c\u4e00\u548c\u7b2c\u4e09\u5217<\/strong><\/h2>\n<p>name_city_columns_by_index = df.iloc[:, [0, 2]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>iloc<\/code>\u65b9\u6cd5\u901a\u8fc7\u7d22\u5f15\u4f4d\u7f6e\u6765\u9009\u62e9\u6570\u636e\uff0c\u8fd9\u5728\u4f60\u9700\u8981\u6839\u636e\u5217\u7684\u4f4d\u7f6e\u800c\u4e0d\u662f\u540d\u79f0\u8fdb\u884c\u9009\u62e9\u65f6\u975e\u5e38\u6709\u7528\u3002\u4f7f\u7528\u4f4d\u7f6e\u7d22\u5f15\u65f6\uff0c\u8981\u6ce8\u610fPython\u7684\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002<\/p>\n<\/p>\n<p><h3>\u901a\u8fc7\u5e03\u5c14\u7d22\u5f15\u9009\u62e9<\/h3>\n<\/p>\n<p><p>\u5e03\u5c14\u7d22\u5f15\u5141\u8bb8\u4f60\u6839\u636e\u6761\u4ef6\u9009\u62e9\u5217\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u67d0\u5217\u7684\u503c\u6765\u9009\u62e9\u5176\u4ed6\u5217\u3002<\/p>\n<\/p>\n<p><h4>3. \u57fa\u4e8e\u6761\u4ef6\u7684\u9009\u62e9<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u5e74\u9f84\u5927\u4e8e30\u7684\u884c\u7684Name\u548cCity\u5217<\/p>\n<p>filtered_df = df[df[&#39;Age&#39;] &gt; 30][[&#39;Name&#39;, &#39;City&#39;]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528\u5e03\u5c14\u6761\u4ef6<code>df[&#39;Age&#39;] &gt; 30<\/code>\u6765\u8fc7\u6ee4\u6570\u636e\u6846\uff0c\u9009\u51fa\u5e74\u9f84\u5927\u4e8e30\u7684\u884c\u3002\u7136\u540e\uff0c\u6211\u4eec\u4ece\u8fc7\u6ee4\u540e\u7684\u6570\u636e\u6846\u4e2d\u9009\u62e9<code>Name<\/code>\u548c<code>City<\/code>\u5217\u3002<strong>\u5e03\u5c14\u7d22\u5f15\u662f\u8fdb\u884c\u6761\u4ef6\u9009\u62e9\u7684\u5f3a\u5927\u5de5\u5177<\/strong>\uff0c\u5c24\u5176\u9002\u5408\u5728\u6570\u636e\u4e2d\u8fdb\u884c\u7b5b\u9009\u548c\u63d0\u53d6\u7279\u5b9a\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u5176\u4ed6\u9ad8\u7ea7\u9009\u62e9\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h4>4. \u4f7f\u7528<code>loc<\/code>\u65b9\u6cd5\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u4e0e<code>iloc<\/code>\u65b9\u6cd5\u7c7b\u4f3c\uff0c<code>loc<\/code>\u65b9\u6cd5\u662f\u57fa\u4e8e\u6807\u7b7e\u7684\u9009\u62e9\u3002\u5b83\u5141\u8bb8\u4f60\u901a\u8fc7\u884c\u6807\u7b7e\u548c\u5217\u6807\u7b7e\u6765\u9009\u62e9\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u6240\u6709\u884c\u7684Name\u548cCity\u5217<\/p>\n<p>name_city_loc = df.loc[:, [&#39;Name&#39;, &#39;City&#39;]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>loc<\/code>\u65b9\u6cd5\u4e0e<code>iloc<\/code>\u7684\u533a\u522b\u5728\u4e8e\uff0c\u5b83\u4f7f\u7528\u7684\u662f\u6807\u7b7e\uff0c\u800c\u4e0d\u662f\u4f4d\u7f6e\u7d22\u5f15\u3002\u8fd9\u4f7f\u5f97\u5b83\u5728\u5904\u7406\u5177\u6709\u7279\u5b9a\u6807\u7b7e\u7684\u6570\u636e\u65f6\u66f4\u52a0\u76f4\u89c2\u548c\u6613\u4e8e\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>5. \u4f7f\u7528<code>filter<\/code>\u65b9\u6cd5\u9009\u62e9<\/h4>\n<\/p>\n<p><p><code>filter<\/code>\u65b9\u6cd5\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u9009\u62e9\u5217\u3002\u5b83\u5141\u8bb8\u4f60\u6839\u636e\u5217\u540d\u7684\u4e00\u90e8\u5206\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u9009\u62e9\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u5217\u540d\u4e2d\u5305\u542b&#39;Name&#39;\u7684\u5217<\/p>\n<p>name_columns = df.filter(like=&#39;Name&#39;)<\/p>\n<h2><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9009\u62e9\u4ee5&#39;C&#39;\u5f00\u5934\u7684\u5217<\/strong><\/h2>\n<p>c_columns = df.filter(regex=&#39;^C&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>filter<\/code>\u65b9\u6cd5\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5f53\u4f60\u9700\u8981\u6839\u636e\u5217\u540d\u7684\u7279\u5b9a\u6a21\u5f0f\u9009\u62e9\u5217\u65f6\u7279\u522b\u6709\u7528\u3002\u5b83\u63d0\u4f9b\u4e86\u5bf9\u5217\u540d\u7684\u6a21\u7cca\u5339\u914d\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><h3>\u901a\u8fc7\u6570\u636e\u6846\u5bf9\u8c61\u7684\u5c5e\u6027\u9009\u62e9<\/h3>\n<\/p>\n<p><h4>6. \u4f7f\u7528\u5c5e\u6027\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u5f53\u6570\u636e\u6846\u7684\u5217\u540d\u662f\u6709\u6548\u7684Python\u6807\u8bc6\u7b26\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c5e\u6027\u7684\u65b9\u5f0f\u6765\u9009\u62e9\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u5355\u5217<\/p>\n<p>age_column_attr = df.Age<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u7f3a\u70b9\u662f\uff0c\u5982\u679c\u5217\u540d\u4e0d\u662f\u6709\u6548\u7684Python\u6807\u8bc6\u7b26\uff0c\u6216\u8005\u5217\u540d\u4e0eDataFrame\u7684\u5176\u4ed6\u65b9\u6cd5\u6216\u5c5e\u6027\u51b2\u7a81\u65f6\uff0c\u5b83\u5c06\u65e0\u6cd5\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u9009\u53d6\u5217\u540e\u7684\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u9009\u53d6\u5217\u540e\uff0c\u4f60\u901a\u5e38\u4f1a\u5bf9\u8fd9\u4e9b\u5217\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u64cd\u4f5c\uff0c\u6bd4\u5982\u6570\u636e\u5206\u6790\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u53d8\u6362\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><h4>7. \u6570\u636e\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u9009\u53d6\u5217\u540e\uff0c\u4f60\u53ef\u4ee5\u5bf9\u8fd9\u4e9b\u5217\u8fdb\u884c\u6570\u636e\u5206\u6790\uff0c\u6bd4\u5982\u8ba1\u7b97\u7edf\u8ba1\u91cf\u3001\u7ed8\u5236\u56fe\u8868\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97Age\u5217\u7684\u5e73\u5747\u503c<\/p>\n<p>average_age = df[&#39;Age&#39;].mean()<\/p>\n<h2><strong>\u7ed8\u5236Age\u5217\u7684\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>df[&#39;Age&#39;].hist()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>8. \u6570\u636e\u6e05\u6d17<\/h4>\n<\/p>\n<p><p>\u5728\u9009\u53d6\u5217\u540e\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u6bd4\u5982\u5904\u7406\u7f3a\u5931\u503c\u3001\u53bb\u9664\u91cd\u590d\u503c\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u586b\u5145Age\u5217\u7684\u7f3a\u5931\u503c<\/p>\n<p>df[&#39;Age&#39;].fillna(df[&#39;Age&#39;].mean(), inplace=True)<\/p>\n<h2><strong>\u53bb\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>df.drop_duplicates(inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>9. \u6570\u636e\u53d8\u6362<\/h4>\n<\/p>\n<p><p>\u9009\u53d6\u5217\u540e\uff0c\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u53d8\u6362\uff0c\u6bd4\u5982\u6570\u636e\u6807\u51c6\u5316\u3001\u521b\u5efa\u884d\u751f\u53d8\u91cf\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6807\u51c6\u5316Age\u5217<\/p>\n<p>df[&#39;Age_standardized&#39;] = (df[&#39;Age&#39;] - df[&#39;Age&#39;].mean()) \/ df[&#39;Age&#39;].std()<\/p>\n<h2><strong>\u521b\u5efa\u884d\u751f\u53d8\u91cf<\/strong><\/h2>\n<p>df[&#39;Age_group&#39;] = df[&#39;Age&#39;].apply(lambda x: &#39;Young&#39; if x &lt; 30 else &#39;Old&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u9009\u62e9\u5217\u7684\u5b9e\u6218\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5217\u7684\u64cd\u4f5c\u901a\u5e38\u4e0e\u5176\u4ed6\u6570\u636e\u64cd\u4f5c\u7ed3\u5408\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b9e\u6218\u4e2d\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<p><h4>10. \u6570\u636e\u5408\u5e76<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u636e\u5408\u5e76\u65f6\uff0c\u901a\u5e38\u9700\u8981\u9009\u62e9\u7279\u5b9a\u7684\u5217\u8fdb\u884c\u5408\u5e76\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u53e6\u4e00\u4e2a\u6570\u636e\u6846<\/p>\n<p>data2 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;],<\/p>\n<p>    &#39;Salary&#39;: [50000, 60000]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u5408\u5e76\u6570\u636e\u6846<\/strong><\/h2>\n<p>merged_df = pd.merge(df, df2, on=&#39;Name&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>11. \u6570\u636e\u900f\u89c6\u8868<\/h4>\n<\/p>\n<p><p>\u5728\u521b\u5efa\u6570\u636e\u900f\u89c6\u8868\u65f6\uff0c\u9700\u8981\u9009\u62e9\u7279\u5b9a\u7684\u5217\u4f5c\u4e3a\u7d22\u5f15\u3001\u5217\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u6570\u636e\u900f\u89c6\u8868<\/p>\n<p>pivot_table = df.pivot_table(index=&#39;City&#39;, columns=&#39;Name&#39;, values=&#39;Age&#39;, aggfunc=&#39;mean&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>12. \u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u65f6\uff0c\u901a\u5e38\u9700\u8981\u9009\u62e9\u7279\u5b9a\u7684\u5217\u8fdb\u884c\u7ed8\u56fe\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236\u67f1\u72b6\u56fe<\/strong><\/h2>\n<p>df.plot(kind=&#39;bar&#39;, x=&#39;Name&#39;, y=&#39;Age&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528Pandas\u5e93\u9009\u53d6\u6570\u636e\u6846\u7684\u4e2a\u522b\u5217\u662f\u4e00\u4e2a\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6280\u80fd\u3002<strong>\u901a\u8fc7\u5217\u540d\u9009\u62e9\u3001\u4f4d\u7f6e\u7d22\u5f15\u9009\u62e9\u3001\u5e03\u5c14\u7d22\u5f15\u9009\u62e9\u3001<code>loc<\/code>\u548c<code>iloc<\/code>\u65b9\u6cd5\u3001<code>filter<\/code>\u65b9\u6cd5\u4ee5\u53ca\u5c5e\u6027\u9009\u62e9<\/strong>\uff0c\u4f60\u53ef\u4ee5\u7075\u6d3b\u5730\u5904\u7406\u548c\u5206\u6790\u6570\u636e\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5217\u7684\u64cd\u4f5c\u901a\u5e38\u4e0e\u6570\u636e\u5206\u6790\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u53d8\u6362\u7b49\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u6570\u636e\u5904\u7406\u4efb\u52a1\u3002\u638c\u63e1\u8fd9\u4e9b\u6280\u672f\u5c06\u6781\u5927\u5730\u63d0\u5347\u4f60\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9009\u53d6DataFrame\u7684\u7279\u5b9a\u5217\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Pandas\u5e93\u53ef\u4ee5\u8f7b\u677e\u9009\u53d6DataFrame\u7684\u7279\u5b9a\u5217\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Pandas\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7<code>import pandas as pd<\/code>\u5bfc\u5165Pandas\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u65b9\u62ec\u53f7\u6765\u9009\u53d6\u4e00\u5217\u6216\u591a\u5217\uff0c\u4f8b\u5982\uff1a<code>df[[&#39;column1&#39;, &#39;column2&#39;]]<\/code>\uff0c\u8fd9\u6837\u5c31\u4f1a\u8fd4\u56de\u5305\u542b\u8fd9\u4e24\u5217\u7684\u65b0DataFrame\u3002<\/p>\n<p><strong>\u5728\u9009\u53d6\u5217\u65f6\uff0c\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u9009\u53d6\u7279\u5b9a\u5217\u65f6\uff0c\u5982\u679c\u60f3\u8981\u5904\u7406\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u5728\u9009\u53d6\u5217\u540e\u4f7f\u7528<code>dropna()<\/code>\u51fd\u6570\u3002\u4f8b\u5982\uff0c<code>df[[&#39;column1&#39;, &#39;column2&#39;]].dropna()<\/code>\u5c06\u8fd4\u56de\u5220\u9664\u7f3a\u5931\u503c\u540e\u7684DataFrame\u3002\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u586b\u5145\u7f3a\u5931\u503c\uff0c\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u6839\u636e\u6761\u4ef6\u9009\u53d6\u7279\u5b9a\u5217\u7684\u503c\uff1f<\/strong><br \/>\u5982\u679c\u5e0c\u671b\u6839\u636e\u67d0\u4e9b\u6761\u4ef6\u9009\u53d6\u7279\u5b9a\u5217\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\u3002\u4f8b\u5982\uff0c<code>df[df[&#39;column1&#39;] &gt; 10][[&#39;column1&#39;, &#39;column2&#39;]]<\/code>\u5c06\u8fd4\u56de<code>column1<\/code>\u5927\u4e8e10\u7684\u884c\uff0c\u5e76\u53ea\u663e\u793a<code>column1<\/code>\u548c<code>column2<\/code>\u8fd9\u4e24\u5217\u3002\u8fd9\u6837\u53ef\u4ee5\u5feb\u901f\u7b5b\u9009\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u9009\u53d6\u6570\u636e\u6846\u7684\u4e2a\u522b\u5217\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u5c24\u5176\u662f\u5728\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u65f6\u3002\u4f7f\u7528Pandas\u5e93\u3001\u901a\u8fc7\u5217\u540d [&hellip;]","protected":false},"author":3,"featured_media":964778,"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\/964775"}],"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=964775"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964775\/revisions"}],"predecessor-version":[{"id":964779,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964775\/revisions\/964779"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/964778"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=964775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=964775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=964775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}