{"id":1144085,"date":"2025-01-08T22:56:35","date_gmt":"2025-01-08T14:56:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1144085.html"},"modified":"2025-01-08T22:56:40","modified_gmt":"2025-01-08T14:56:40","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b4%e6%95%b0%e8%bd%ac%e5%8c%96%e4%b8%ba%e7%99%be%e5%88%86%e6%af%94","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1144085.html","title":{"rendered":"python\u5982\u4f55\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181351\/4c0b6987-2f2a-457e-be39-431c2b2d8fce.webp\" alt=\"python\u5982\u4f55\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\" \/><\/p>\n<p><p> <strong>Python \u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u3001\u5229\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u501f\u52a9 Python \u7684\u5185\u7f6e\u51fd\u6570\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u76f8\u5bf9\u7b80\u5355\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<strong>\u5229\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/strong> \u662f\u4e00\u79cd\u975e\u5e38\u7b80\u6d01\u4e14\u6613\u4e8e\u9605\u8bfb\u7684\u65b9\u5f0f\u3002\u5728 Python \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u8bed\u6cd5\uff08\u4f8b\u5982 f-string \u6216 format \u65b9\u6cd5\uff09\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u6574\u6570 75\uff0c\u5e76\u5e0c\u671b\u5c06\u5176\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u8868\u793a\u5f62\u5f0f\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = f&quot;{number}%&quot;<\/p>\n<p>print(percentage)  # \u8f93\u51fa\uff1a75%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4ee3\u7801\u975e\u5e38\u7b80\u6d01\u660e\u4e86\uff0c\u4e14\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u662f\u901a\u8fc7\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u6574\u6570\u5e76\u5e0c\u671b\u5c06\u5176\u8868\u793a\u4e3a\u767e\u5206\u6bd4\uff0c\u53ea\u9700\u5c06\u8be5\u6574\u6570\u9664\u4ee5 100 \u5e76\u9644\u52a0\u767e\u5206\u53f7\u5373\u53ef\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = number \/ 100<\/p>\n<p>print(f&quot;{percentage * 100}%&quot;)  # \u8f93\u51fa\uff1a75.0%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u663e\u5f97\u6709\u4e9b\u7e41\u7410\uff0c\u7279\u522b\u662f\u5f53\u4f60\u9700\u8981\u5904\u7406\u591a\u4e2a\u6574\u6570\u65f6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u662f Python \u4e2d\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5b83\u5141\u8bb8\u4f60\u5728\u5b57\u7b26\u4e32\u4e2d\u5d4c\u5165\u53d8\u91cf\uff0c\u5e76\u53ef\u4ee5\u6307\u5b9a\u683c\u5f0f\u3002\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u4e0d\u4ec5\u7b80\u5355\u800c\u4e14\u6e05\u6670\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u683c\u5f0f\u5316\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528 f-string<\/h4>\n<\/p>\n<p><p>f-string \u662f Python 3.6 \u5f15\u5165\u7684\u4e00\u79cd\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u5b83\u7684\u8bed\u6cd5\u975e\u5e38\u7b80\u6d01\u660e\u4e86\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 f-string \u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = f&quot;{number}%&quot;<\/p>\n<p>print(percentage)  # \u8f93\u51fa\uff1a75%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528 format \u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>format \u65b9\u6cd5\u662f Python 3 \u4e2d\u7684\u4e00\u79cd\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u5b83\u540c\u6837\u975e\u5e38\u7075\u6d3b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = &quot;{}%&quot;.format(number)<\/p>\n<p>print(percentage)  # \u8f93\u51fa\uff1a75%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u4f7f\u7528\u767e\u5206\u6bd4\u683c\u5f0f\u5316<\/h4>\n<\/p>\n<p><p>\u5728 Python \u4e2d\uff0c\u767e\u5206\u6bd4\u683c\u5f0f\u5316\u662f\u4e00\u79cd\u975e\u5e38\u4f20\u7edf\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u5b83\u4f7f\u7528 <code>%<\/code> \u64cd\u4f5c\u7b26\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = &quot;%d%%&quot; % number<\/p>\n<p>print(percentage)  # \u8f93\u51fa\uff1a75%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u501f\u52a9 Python \u7684\u5185\u7f6e\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python \u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u5404\u79cd\u7c7b\u578b\u7684\u8f6c\u6362\u3002\u867d\u7136\u6ca1\u6709\u76f4\u63a5\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u5e38\u89c1\u7684\u51fd\u6570\u6765\u7b80\u5316\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528 round \u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u5e0c\u671b\u5c06\u767e\u5206\u6bd4\u8868\u793a\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u800c\u4e0d\u662f\u6d6e\u70b9\u6570\u3002\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528 round \u51fd\u6570\u8fdb\u884c\u56db\u820d\u4e94\u5165\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = round(number \/ 100, 2) * 100<\/p>\n<p>print(f&quot;{percentage}%&quot;)  # \u8f93\u51fa\uff1a75.0%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528 int \u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5e0c\u671b\u767e\u5206\u6bd4\u59cb\u7ec8\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 int \u51fd\u6570\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">number = 75<\/p>\n<p>percentage = int(number \/ 100 * 100)<\/p>\n<p>print(f&quot;{percentage}%&quot;)  # \u8f93\u51fa\uff1a75%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u5728\u8bb8\u591a\u5b9e\u9645\u5e94\u7528\u4e2d\u90fd\u662f\u975e\u5e38\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<p><h4>1. \u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u53ef\u89c6\u5316\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u5c06\u6570\u636e\u8868\u793a\u4e3a\u767e\u5206\u6bd4\uff0c\u4ee5\u4fbf\u66f4\u76f4\u89c2\u5730\u5c55\u793a\u6570\u636e\u3002\u4f8b\u5982\uff0c\u5728\u7ed8\u5236\u997c\u56fe\u65f6\uff0c\u5c06\u5404\u4e2a\u90e8\u5206\u7684\u6570\u503c\u8868\u793a\u4e3a\u767e\u5206\u6bd4\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u7406\u89e3\u6570\u636e\u5206\u5e03\u3002<\/p>\n<\/p>\n<p><h4>2. \u7edf\u8ba1\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5728\u7edf\u8ba1\u5206\u6790\u4e2d\uff0c\u767e\u5206\u6bd4\u662f\u4e00\u79cd\u975e\u5e38\u5e38\u7528\u7684\u8868\u793a\u65b9\u6cd5\u3002\u901a\u8fc7\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\uff0c\u53ef\u4ee5\u66f4\u6e05\u6670\u5730\u5c55\u793a\u6570\u636e\u7684\u6bd4\u4f8b\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5728\u5206\u6790\u5e02\u573a\u4efd\u989d\u65f6\uff0c\u53ef\u4ee5\u5c06\u5404\u4e2a\u516c\u53f8\u7684\u9500\u552e\u989d\u8868\u793a\u4e3a\u767e\u5206\u6bd4\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><h4>3. \u8d22\u52a1\u62a5\u8868<\/h4>\n<\/p>\n<p><p>\u5728\u8d22\u52a1\u62a5\u8868\u4e2d\uff0c\u767e\u5206\u6bd4\u5e38\u7528\u4e8e\u8868\u793a\u5404\u79cd\u6bd4\u4f8b\u5173\u7cfb\uff0c\u4f8b\u5982\u6bdb\u5229\u7387\u3001\u51c0\u5229\u7387\u7b49\u3002\u901a\u8fc7\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\uff0c\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u5c55\u793a\u4f01\u4e1a\u7684\u8d22\u52a1\u72b6\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u65f6\uff0c\u6709\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879\uff1a<\/p>\n<\/p>\n<p><h4>1. \u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u6570\u636e\u7c7b\u578b\u7684\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u5e0c\u671b\u5f97\u5230\u4e00\u4e2a\u6574\u6570\u767e\u5206\u6bd4\uff0c\u9700\u8981\u786e\u4fdd\u8fdb\u884c\u76f8\u5e94\u7684\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>2. \u7cbe\u5ea6<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u4fdd\u7559\u4e00\u5b9a\u7684\u7cbe\u5ea6\u3002\u4f8b\u5982\uff0c\u5728\u8d22\u52a1\u62a5\u8868\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u8f6c\u6362\u65f6\u9700\u8981\u8003\u8651\u7cbe\u5ea6\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>3. \u683c\u5f0f\u5316<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u683c\u5f0f\u7684\u6b63\u786e\u6027\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528\u767e\u5206\u6bd4\u683c\u5f0f\u5316\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u767e\u5206\u53f7\u7684\u6b63\u786e\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u5728 Python \u4e2d\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4f9b\u9009\u62e9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<strong>\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u975e\u5e38\u7b80\u6d01\u4e14\u6613\u4e8e\u9605\u8bfb\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u573a\u666f\u3002<\/strong>\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u548c\u5185\u7f6e\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u64cd\u4f5c\u3002\u65e0\u8bba\u91c7\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u9700\u8981\u6ce8\u610f\u6570\u636e\u7c7b\u578b\u3001\u7cbe\u5ea6\u548c\u683c\u5f0f\u5316\u7b49\u95ee\u9898\uff0c\u4ee5\u786e\u4fdd\u8f6c\u6362\u7ed3\u679c\u7684\u6b63\u786e\u6027\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u6709\u52a9\u4e8e\u66f4\u76f4\u89c2\u5730\u5c55\u793a\u6570\u636e\uff0c\u4fbf\u4e8e\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u51b3\u7b56\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u767e\u5206\u6bd4\u683c\u5f0f\uff1f<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6216\u5b57\u7b26\u4e32\u7684<code>format<\/code>\u65b9\u6cd5\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u767e\u5206\u6bd4\u683c\u5f0f\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e58\u4ee5100\u5e76\u6dfb\u52a0\u201c%\u201d\u7b26\u53f7\uff0c\u6765\u5b9e\u73b0\u5bf9\u6574\u6570\u7684\u767e\u5206\u6bd4\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">integer_value = 0.85  # \u8fd9\u4e2a\u503c\u8868\u793a85%\npercentage = &quot;{:.2f}%&quot;.format(integer_value * 100)\nprint(percentage)  # \u8f93\u51fa 85.00%\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u786e\u4fdd\u8f93\u51fa\u7684\u5c0f\u6570\u70b9\u540e\u6709\u4e24\u4f4d\u6570\u5b57\uff0c\u5e76\u9644\u52a0\u4e0a\u201c%\u201d\u7b26\u53f7\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u5c0f\u6570\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u767e\u5206\u6bd4\uff1f<\/strong><\/p>\n<p>\u5728\u5904\u7406\u5c0f\u6570\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06\u5c0f\u6570\u4e58\u4ee5100\u5e76\u683c\u5f0f\u5316\u4e3a\u767e\u5206\u6bd4\u3002\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5c0f\u6570\uff0c\u59820.75\uff0c\u8f6c\u6362\u4e3a\u767e\u5206\u6bd4\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">decimal_value = 0.75\npercentage = f&quot;{decimal_value * 100:.1f}%&quot;\nprint(percentage)  # \u8f93\u51fa 75.0%\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u7528\u4e86f-string\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7b80\u6d01\u7684\u8bed\u6cd5\u6765\u5b9e\u73b0\u683c\u5f0f\u5316\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u5e93\u53ef\u4ee5\u7b80\u5316Python\u4e2d\u767e\u5206\u6bd4\u7684\u8ba1\u7b97\u548c\u663e\u793a\uff1f<\/strong><\/p>\n<p>\u662f\u7684\uff0cPython\u4e2d\u6709\u4e00\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u7b80\u5316\u767e\u5206\u6bd4\u7684\u8ba1\u7b97\u548c\u663e\u793a\u3002\u4f8b\u5982\uff0c<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5904\u7406\u6570\u636e\u5e76\u4ee5\u767e\u5206\u6bd4\u5f62\u5f0f\u5c55\u793a\u3002\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u7684<code>apply<\/code>\u65b9\u6cd5\u6765\u5bf9\u6570\u636e\u6846\u4e2d\u7684\u5217\u8fdb\u884c\u767e\u5206\u6bd4\u8f6c\u6362\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = {&#39;values&#39;: [0.2, 0.5, 0.75]}\ndf = pd.DataFrame(data)\ndf[&#39;percentage&#39;] = df[&#39;values&#39;].apply(lambda x: f&quot;{x * 100:.2f}%&quot;)\nprint(df)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u8fd8\u80fd\u6709\u6548\u5904\u7406\u66f4\u590d\u6742\u7684\u6570\u636e\u96c6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python \u5c06\u6574\u6570\u8f6c\u5316\u4e3a\u767e\u5206\u6bd4\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u3001\u5229\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u501f\u52a9 Python \u7684\u5185\u7f6e [&hellip;]","protected":false},"author":3,"featured_media":1144103,"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\/1144085"}],"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=1144085"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144085\/revisions"}],"predecessor-version":[{"id":1144104,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144085\/revisions\/1144104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1144103"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1144085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1144085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1144085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}