{"id":1101231,"date":"2025-01-08T15:47:26","date_gmt":"2025-01-08T07:47:26","guid":{"rendered":""},"modified":"2025-01-08T15:47:30","modified_gmt":"2025-01-08T07:47:30","slug":"%e5%9c%a8python%e4%b8%ad%e5%a6%82%e4%bd%95%e6%96%b0%e5%8a%a0%e4%b8%80%e5%88%97-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1101231.html","title":{"rendered":"\u5728python\u4e2d\u5982\u4f55\u65b0\u52a0\u4e00\u5217"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064108\/0f92da2f-0fb4-435d-ab33-6b247deb99bc.webp\" alt=\"\u5728python\u4e2d\u5982\u4f55\u65b0\u52a0\u4e00\u5217\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6dfb\u52a0\u65b0\u5217\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528pandas\u5e93\u521b\u5efa\u65b0\u5217\u3001\u901a\u8fc7numpy\u8fdb\u884c\u64cd\u4f5c\u3001\u57fa\u4e8e\u6761\u4ef6\u521b\u5efa\u65b0\u5217<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7pandas\u5e93\u6765\u5904\u7406\u3002pandas\u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pandas\u6765\u6dfb\u52a0\u65b0\u5217\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528pandas\u5e93\u521b\u5efa\u65b0\u5217<\/h2>\n<\/p>\n<p><p>pandas\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u5206\u6790\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\u3002\u4f7f\u7528pandas\u521b\u5efa\u65b0\u5217\u975e\u5e38\u7b80\u5355\uff0c\u901a\u5e38\u901a\u8fc7DataFrame\u5bf9\u8c61\u7684\u8d4b\u503c\u64cd\u4f5c\u6765\u5b9e\u73b0\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u6dfb\u52a0\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;salary&#39;] = [50000, 60000, 70000]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u7684DataFrame\uff0c\u7136\u540e\u901a\u8fc7\u8d4b\u503c\u64cd\u4f5c\u6dfb\u52a0\u4e86\u4e00\u4e2a\u5305\u542b\u5de5\u8d44\u7684\u65b0\u5217\u3002<strong>\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\u4e14\u6613\u4e8e\u7406\u89e3\uff0c\u662f\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u4e4b\u4e00<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528numpy\u5e93\u521b\u5efa\u65b0\u5217<\/h2>\n<\/p>\n<p><p>numpy\u662fPython\u4e2d\u7684\u4e00\u4e2a\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u65b9\u6cd5\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528numpy\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528numpy\u521b\u5efa\u65b0\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/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>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u4f7f\u7528numpy\u521b\u5efa\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;salary&#39;] = np.array([50000, 60000, 70000])<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0epandas\u7c7b\u4f3c\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u7684DataFrame\u3002\u7136\u540e\u6211\u4eec\u4f7f\u7528numpy\u6570\u7ec4\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u5de5\u8d44\u7684\u65b0\u5217\u3002<strong>\u8fd9\u79cd\u65b9\u6cd5\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\uff0c\u6548\u7387\u66f4\u9ad8<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u57fa\u4e8e\u6761\u4ef6\u521b\u5efa\u65b0\u5217<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u7684\u6570\u636e\u5904\u7406\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u57fa\u4e8e\u67d0\u4e9b\u6761\u4ef6\u6765\u521b\u5efa\u65b0\u5217\u3002pandas\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u6761\u4ef6\u5224\u65ad\u548c\u6570\u636e\u64cd\u4f5c\u65b9\u6cd5\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u57fa\u4e8e\u6761\u4ef6\u521b\u5efa\u65b0\u5217\u7684\u793a\u4f8b\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u57fa\u4e8e\u6761\u4ef6\u521b\u5efa\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;is_adult&#39;] = df[&#39;age&#39;].apply(lambda x: x &gt;= 18)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u57fa\u4e8e\u5e74\u9f84\u5217\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5e03\u5c14\u5217<code>is_adult<\/code>\uff0c\u5224\u65ad\u6bcf\u4e2a\u4eba\u662f\u5426\u6210\u5e74\u3002<strong>\u8fd9\u79cd\u57fa\u4e8e\u6761\u4ef6\u7684\u65b9\u6cd5\u975e\u5e38\u7075\u6d3b\uff0c\u53ef\u4ee5\u5e94\u7528\u4e8e\u5404\u79cd\u590d\u6742\u7684\u6570\u636e\u5904\u7406\u573a\u666f<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528DataFrame\u7684\u5185\u7f6e\u65b9\u6cd5\u521b\u5efa\u65b0\u5217<\/h2>\n<\/p>\n<p><p>pandas\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u65b9\u6cd5\uff0c\u7528\u4e8e\u6839\u636e\u73b0\u6709\u6570\u636e\u521b\u5efa\u65b0\u5217\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>DataFrame.assign()<\/code>\u65b9\u6cd5\u6765\u6dfb\u52a0\u65b0\u5217\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u4f7f\u7528assign\u65b9\u6cd5\u521b\u5efa\u65b0\u5217<\/strong><\/h2>\n<p>df = df.assign(salary=[50000, 60000, 70000])<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>assign<\/code>\u65b9\u6cd5\u5141\u8bb8\u6211\u4eec\u5728\u94fe\u5f0f\u64cd\u4f5c\u4e2d\u6dfb\u52a0\u65b0\u5217\uff0c<strong>\u8fd9\u5bf9\u4e8e\u9700\u8981\u591a\u6b65\u9aa4\u5904\u7406\u7684\u6570\u636e\u7ba1\u9053\u975e\u5e38\u6709\u7528<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528\u5b57\u5178\u6620\u5c04\u6dfb\u52a0\u65b0\u5217<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u6839\u636e\u5b57\u5178\u6620\u5c04\u6765\u6dfb\u52a0\u65b0\u5217\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u57fa\u4e8e\u5b57\u5178\u6620\u5c04\u6dfb\u52a0\u65b0\u5217\u7684\u793a\u4f8b\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u521b\u5efa\u5b57\u5178\u6620\u5c04<\/strong><\/h2>\n<p>salary_mapping = {<\/p>\n<p>    &#39;Alice&#39;: 50000,<\/p>\n<p>    &#39;Bob&#39;: 60000,<\/p>\n<p>    &#39;Charlie&#39;: 70000<\/p>\n<p>}<\/p>\n<h2><strong>\u4f7f\u7528map\u65b9\u6cd5\u6dfb\u52a0\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;salary&#39;] = df[&#39;name&#39;].map(salary_mapping)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5b57\u5178\u6620\u5c04\u548c<code>map<\/code>\u65b9\u6cd5\uff0c\u6839\u636e\u59d3\u540d\u5217\u4e3a\u6bcf\u4e2a\u4eba\u6dfb\u52a0\u4e86\u76f8\u5e94\u7684\u5de5\u8d44\u3002<strong>\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4e8e\u9700\u8981\u6839\u636e\u5916\u90e8\u6570\u636e\u6dfb\u52a0\u65b0\u5217\u7684\u60c5\u51b5\u975e\u5e38\u6709\u7528<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u6839\u636e\u73b0\u6709\u5217\u7684\u8ba1\u7b97\u7ed3\u679c\u521b\u5efa\u65b0\u5217<\/h2>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u73b0\u6709\u5217\u7684\u8ba1\u7b97\u7ed3\u679c\u6765\u521b\u5efa\u65b0\u5217\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u6839\u636e\u73b0\u6709\u5217\u7684\u8ba1\u7b97\u7ed3\u679c\u521b\u5efa\u65b0\u5217\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35],<\/p>\n<p>    &#39;salary&#39;: [50000, 60000, 70000]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u6839\u636e\u73b0\u6709\u5217\u7684\u8ba1\u7b97\u7ed3\u679c\u521b\u5efa\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;salary_per_year&#39;] = df[&#39;salary&#39;] * df[&#39;age&#39;]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u6839\u636e\u5de5\u8d44\u548c\u5e74\u9f84\u7684\u4e58\u79ef\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5217<code>salary_per_year<\/code>\u3002<strong>\u8fd9\u79cd\u65b9\u6cd5\u5728\u9700\u8981\u8fdb\u884c\u5217\u95f4\u8ba1\u7b97\u65f6\u975e\u5e38\u6709\u7528<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u4f7f\u7528apply\u65b9\u6cd5\u6dfb\u52a0\u65b0\u5217<\/h2>\n<\/p>\n<p><p><code>apply<\/code>\u65b9\u6cd5\u662fpandas\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5c06\u4efb\u610f\u51fd\u6570\u5e94\u7528\u5230DataFrame\u7684\u884c\u6216\u5217\u4e0a\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>apply<\/code>\u65b9\u6cd5\u6dfb\u52a0\u65b0\u5217\u7684\u793a\u4f8b\uff1a<\/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;name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;age&#39;: [25, 30, 35],<\/p>\n<p>    &#39;salary&#39;: [50000, 60000, 70000]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/strong><\/h2>\n<p>def calculate_bonus(row):<\/p>\n<p>    return row[&#39;salary&#39;] * 0.1<\/p>\n<h2><strong>\u4f7f\u7528apply\u65b9\u6cd5\u6dfb\u52a0\u65b0\u5217<\/strong><\/h2>\n<p>df[&#39;bonus&#39;] = df.apply(calculate_bonus, axis=1)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u8ba1\u7b97\u5956\u91d1\u7684\u51fd\u6570\uff0c\u5e76\u4f7f\u7528<code>apply<\/code>\u65b9\u6cd5\u5c06\u5176\u5e94\u7528\u5230\u6bcf\u4e00\u884c\u4e0a\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u5956\u91d1\u7684\u65b0\u5217\u3002<strong>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u8fdb\u884c\u590d\u6742\u8ba1\u7b97\u6216\u8de8\u5217\u64cd\u4f5c\u7684\u60c5\u51b5<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5728Python\u4e2d\u6dfb\u52a0\u65b0\u5217\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528pandas\u5e93\u521b\u5efa\u65b0\u5217\u3001\u901a\u8fc7numpy\u8fdb\u884c\u64cd\u4f5c\u3001\u57fa\u4e8e\u6761\u4ef6\u521b\u5efa\u65b0\u5217\u3001\u4f7f\u7528DataFrame\u7684\u5185\u7f6e\u65b9\u6cd5\u521b\u5efa\u65b0\u5217\u3001\u6839\u636e\u5b57\u5178\u6620\u5c04\u6dfb\u52a0\u65b0\u5217\u3001\u6839\u636e\u73b0\u6709\u5217\u7684\u8ba1\u7b97\u7ed3\u679c\u521b\u5efa\u65b0\u5217\u4ee5\u53ca\u4f7f\u7528apply\u65b9\u6cd5\u6dfb\u52a0\u65b0\u5217\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u70b9\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u548c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u5728Python\u4e2d\u6dfb\u52a0\u65b0\u5217\u7684\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\u5982\u4f55\u5411DataFrame\u6dfb\u52a0\u65b0\u5217\uff1f<\/strong><br \/>\u8981\u5411Pandas DataFrame\u6dfb\u52a0\u65b0\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b80\u5355\u7684\u8d4b\u503c\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5217\u5e76\u8d4b\u503c\uff1a<code>df[&#39;\u65b0\u5217\u540d&#39;] = \u503c<\/code>\u3002\u503c\u53ef\u4ee5\u662f\u4e00\u4e2a\u5e38\u91cf\u3001\u4e00\u4e2a\u5217\u8868\u6216\u662f\u4e00\u4e2aSeries\u3002\u786e\u4fdd\u65b0\u5217\u7684\u957f\u5ea6\u4e0eDataFrame\u4e2d\u7684\u884c\u6570\u5339\u914d\uff0c\u4ee5\u907f\u514d\u9519\u8bef\u3002<\/p>\n<p><strong>\u5982\u4f55\u6839\u636e\u5df2\u6709\u5217\u7684\u503c\u8ba1\u7b97\u65b0\u5217\u7684\u503c\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Pandas\u63d0\u4f9b\u7684\u5411\u91cf\u5316\u64cd\u4f5c\u6765\u6839\u636e\u5df2\u6709\u5217\u7684\u503c\u8ba1\u7b97\u65b0\u5217\u7684\u503c\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u5217\u201c\u9500\u552e\u989d\u201d\uff0c\u53ef\u4ee5\u521b\u5efa\u65b0\u5217\u201c\u7a0e\u540e\u9500\u552e\u989d\u201d\uff0c\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a<code>df[&#39;\u7a0e\u540e\u9500\u552e\u989d&#39;] = df[&#39;\u9500\u552e\u989d&#39;] * 0.9<\/code>\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u9ad8\u6548\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u6dfb\u52a0\u65b0\u5217\u65f6\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u6dfb\u52a0\u65b0\u5217\u65f6\uff0c\u5982\u679c\u6d89\u53ca\u5230\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u6765\u5904\u7406\u3002\u4f8b\u5982\uff0c\u5728\u521b\u5efa\u65b0\u5217\u524d\u53ef\u4ee5\u5bf9\u5df2\u6709\u5217\u8fdb\u884c\u7f3a\u5931\u503c\u586b\u5145\uff1a<code>df[&#39;\u5df2\u6709\u5217&#39;].fillna(0, inplace=True)<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5728\u8ba1\u7b97\u65b0\u5217\u65f6\u4e0d\u4f1a\u51fa\u73b0\u9519\u8bef\u6216\u610f\u5916\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6dfb\u52a0\u65b0\u5217\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528pandas\u5e93\u521b\u5efa\u65b0\u5217\u3001\u901a\u8fc7numpy\u8fdb\u884c\u64cd\u4f5c\u3001\u57fa\u4e8e\u6761\u4ef6\u521b [&hellip;]","protected":false},"author":3,"featured_media":1101241,"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\/1101231"}],"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=1101231"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101231\/revisions"}],"predecessor-version":[{"id":1101245,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101231\/revisions\/1101245"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1101241"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1101231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1101231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1101231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}