{"id":1036780,"date":"2024-12-31T12:09:40","date_gmt":"2024-12-31T04:09:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1036780.html"},"modified":"2024-12-31T12:09:42","modified_gmt":"2024-12-31T04:09:42","slug":"python%e5%a6%82%e4%bd%95%e9%81%8d%e5%8e%86%e5%ad%97%e5%85%b8%e4%b8%ad%e5%88%97%e7%9a%84%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1036780.html","title":{"rendered":"Python\u5982\u4f55\u904d\u5386\u5b57\u5178\u4e2d\u5217\u7684\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/b9f01581-99a9-4684-8270-4bb3b1a49237.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Python\u5982\u4f55\u904d\u5386\u5b57\u5178\u4e2d\u5217\u7684\u503c\" \/><\/p>\n<p><p> <strong>Python\u904d\u5386\u5b57\u5178\u4e2d\u5217\u7684\u503c\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u3001\u4f7f\u7528\u5b57\u5178\u7684keys()\u65b9\u6cd5\u3001\u4f7f\u7528\u5b57\u5178\u7684values()\u65b9\u6cd5\u3001\u4f7f\u7528items()\u65b9\u6cd5\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u7684\u65b9\u6cd5\u6700\u4e3a\u5e38\u89c1\u548c\u76f4\u89c2\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u7684\u4f7f\u7528\u53ca\u5176\u4f18\u7f3a\u70b9\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9<\/p>\n<\/p>\n<p><p>\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u5b57\u5178\u4e2d\u7684\u952e\u503c\u5bf9\u662f\u4e00\u79cd\u76f4\u63a5\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u5b57\u5178\u7684\u9879\u6765\u8bbf\u95ee\u6bcf\u4e2a\u952e\u548c\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u7b80\u6d01\u3001\u6613\u8bfb\uff0c\u9002\u5408\u5927\u591a\u6570\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>for key in my_dict:<\/p>\n<p>    value = my_dict[key]<\/p>\n<p>    print(f&quot;Key: {key}, Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u7b80\u5355\u76f4\u89c2\uff0c\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\u3002\u7f3a\u70b9\u662f\u5982\u679c\u5b57\u5178\u5f88\u5927\uff0c\u904d\u5386\u6240\u6709\u952e\u503c\u5bf9\u53ef\u80fd\u4f1a\u5f71\u54cd\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5b57\u5178\u7684keys()\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5b57\u5178\u7684keys()\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u952e\u7684\u89c6\u56fe\u5bf9\u8c61\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u8fd9\u4e2a\u89c6\u56fe\u5bf9\u8c61\u6765\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u952e\u548c\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u660e\u786e\u5730\u8868\u660e\u6211\u4eec\u53ea\u5173\u5fc3\u5b57\u5178\u7684\u952e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>for key in my_dict.keys():<\/p>\n<p>    value = my_dict[key]<\/p>\n<p>    print(f&quot;Key: {key}, Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u4ee3\u7801\u53ef\u8bfb\u6027\u9ad8\uff0c\u5bb9\u6613\u7406\u89e3\u3002\u7f3a\u70b9\u662f\u4e0e\u76f4\u63a5\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u76f8\u6bd4\uff0c\u6ca1\u6709\u663e\u8457\u4f18\u52bf\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u5b57\u5178\u7684values()\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5b57\u5178\u7684values()\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u503c\u7684\u89c6\u56fe\u5bf9\u8c61\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u8fd9\u4e2a\u89c6\u56fe\u5bf9\u8c61\u6765\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u503c\uff0c\u800c\u4e0d\u9700\u8981\u5173\u5fc3\u952e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>for value in my_dict.values():<\/p>\n<p>    print(f&quot;Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u5982\u679c\u53ea\u5173\u5fc3\u5b57\u5178\u4e2d\u7684\u503c\uff0c\u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\u3002\u7f3a\u70b9\u662f\u65e0\u6cd5\u540c\u65f6\u83b7\u53d6\u952e\u548c\u503c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528items()\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5b57\u5178\u7684items()\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u952e\u503c\u5bf9\u7684\u89c6\u56fe\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u952e\u503c\u5bf9\u4ee5\u5143\u7ec4\u7684\u5f62\u5f0f\u5b58\u50a8\u3002\u901a\u8fc7\u904d\u5386\u8fd9\u4e2a\u89c6\u56fe\u5bf9\u8c61\uff0c\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u952e\u548c\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u7b80\u6d01\u4e14\u53ef\u4ee5\u540c\u65f6\u83b7\u53d6\u952e\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>for key, value in my_dict.items():<\/p>\n<p>    print(f&quot;Key: {key}, Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u4ee3\u7801\u7b80\u6d01\u3001\u6613\u8bfb\uff0c\u53ef\u4ee5\u540c\u65f6\u83b7\u53d6\u952e\u548c\u503c\uff0c\u9002\u5408\u5927\u591a\u6570\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\u4e0e\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u76f8\u6bd4\uff0c\u6027\u80fd\u4e0a\u6ca1\u6709\u663e\u8457\u63d0\u5347\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528enumerate()\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728\u904d\u5386\u5b57\u5178\u65f6\u83b7\u53d6\u7d22\u5f15\u3002\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528enumerate()\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u7d22\u5f15\u548c\u503c\u7684\u8fed\u4ee3\u5668\u3002\u901a\u8fc7\u904d\u5386\u8fd9\u4e2a\u8fed\u4ee3\u5668\uff0c\u53ef\u4ee5\u540c\u65f6\u83b7\u53d6\u7d22\u5f15\u3001\u952e\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>for index, (key, value) in enumerate(my_dict.items()):<\/p>\n<p>    print(f&quot;Index: {index}, Key: {key}, Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u5982\u679c\u9700\u8981\u7d22\u5f15\u4fe1\u606f\uff0c\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u3002\u7f3a\u70b9\u662f\u4ee3\u7801\u7a0d\u663e\u590d\u6742\uff0c\u4e0d\u9002\u5408\u9700\u8981\u7b80\u6d01\u4ee3\u7801\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f<\/p>\n<\/p>\n<p><p>\u5b57\u5178\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u53ef\u4ee5\u5728\u904d\u5386\u5b57\u5178\u65f6\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u5982\u8fc7\u6ee4\u6216\u8f6c\u6362\u952e\u503c\u5bf9\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u904d\u5386\u5b57\u5178\u7684\u540c\u65f6\u5b8c\u6210\u4e00\u4e9b\u989d\u5916\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<h2><strong>\u793a\u4f8b\uff1a\u5c06\u503c\u52a0\u500d<\/strong><\/h2>\n<p>new_dict = {key: value * 2 for key, value in my_dict.items()}<\/p>\n<p>print(new_dict)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u4ee3\u7801\u7b80\u6d01\u3001\u76f4\u89c2\uff0c\u9002\u5408\u9700\u8981\u5728\u904d\u5386\u5b57\u5178\u65f6\u8fdb\u884c\u4e00\u4e9b\u989d\u5916\u64cd\u4f5c\u7684\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\u5bf9\u4e8e\u590d\u6742\u64cd\u4f5c\uff0c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u53ef\u80fd\u4f1a\u4e0b\u964d\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528itertools\u6a21\u5757<\/p>\n<\/p>\n<p><p>itertools\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ad8\u6548\u7684\u8fed\u4ee3\u5668\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u904d\u5386\u5b57\u5178\u65f6\u63d0\u9ad8\u6027\u80fd\u3002\u7279\u522b\u662f\u5bf9\u4e8e\u5927\u5b57\u5178\uff0c\u4f7f\u7528itertools\u6a21\u5757\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u904d\u5386\u6548\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>import itertools<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<h2><strong>\u793a\u4f8b\uff1a\u6279\u91cf\u5904\u7406\u952e\u503c\u5bf9<\/strong><\/h2>\n<p>for chunk in itertools.islice(my_dict.items(), 2):<\/p>\n<p>    print(chunk)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u53ef\u4ee5\u9ad8\u6548\u5904\u7406\u5927\u5b57\u5178\uff0c\u9002\u5408\u9700\u8981\u63d0\u5347\u6027\u80fd\u7684\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\u4ee3\u7801\u76f8\u5bf9\u590d\u6742\uff0c\u4e0d\u9002\u5408\u521d\u5b66\u8005\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u4f7f\u7528pandas\u5e93<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u590d\u6742\u6570\u636e\u7ed3\u6784\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528pandas\u5e93\u3002pandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u904d\u5386\u548c\u64cd\u4f5c\u5b57\u5178\u6570\u636e\u3002\u7279\u522b\u662f\u5728\u5904\u7406\u6570\u636e\u5206\u6790\u4efb\u52a1\u65f6\uff0cpandas\u5e93\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>import pandas as pd<\/p>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>df = pd.DataFrame(list(my_dict.items()), columns=[&#39;Key&#39;, &#39;Value&#39;])<\/p>\n<h2><strong>\u904d\u5386DataFrame<\/strong><\/h2>\n<p>for index, row in df.iterrows():<\/p>\n<p>    print(f&quot;Key: {row[&#39;Key&#39;]}, Value: {row[&#39;Value&#39;]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8epandas\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u9002\u5408\u9700\u8981\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u7684\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\u5f15\u5165\u4e86\u989d\u5916\u7684\u4f9d\u8d56\uff0c\u5bf9\u4e8e\u7b80\u5355\u4efb\u52a1\u53ef\u80fd\u663e\u5f97\u8fc7\u4e8e\u590d\u6742\u3002<\/p>\n<\/p>\n<p><p>\u4e5d\u3001\u901a\u8fc7\u51fd\u6570\u9012\u5f52\u904d\u5386\u5d4c\u5957\u5b57\u5178<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5d4c\u5957\u5b57\u5178\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u904d\u5386\u6240\u6709\u5c42\u7ea7\u7684\u952e\u503c\u5bf9\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u53ef\u4ee5\u5904\u7406\u4efb\u610f\u6df1\u5ea6\u7684\u5d4c\u5957\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u4ee3\u7801<\/p>\n<p>def traverse_dict(d, parent_key=&#39;&#39;):<\/p>\n<p>    for key, value in d.items():<\/p>\n<p>        new_key = f&quot;{parent_key}.{key}&quot; if parent_key else key<\/p>\n<p>        if isinstance(value, dict):<\/p>\n<p>            traverse_dict(value, new_key)<\/p>\n<p>        else:<\/p>\n<p>            print(f&quot;Key: {new_key}, Value: {value}&quot;)<\/p>\n<p>nested_dict = {&#39;a&#39;: {&#39;b&#39;: 1, &#39;c&#39;: {&#39;d&#39;: 2}}, &#39;e&#39;: 3}<\/p>\n<p>traverse_dict(nested_dict)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u53ef\u4ee5\u5904\u7406\u4efb\u610f\u6df1\u5ea6\u7684\u5d4c\u5957\u5b57\u5178\uff0c\u9002\u5408\u590d\u6742\u6570\u636e\u7ed3\u6784\u7684\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\u9012\u5f52\u51fd\u6570\u7684\u5b9e\u73b0\u76f8\u5bf9\u590d\u6742\uff0c\u4e0d\u9002\u5408\u7b80\u5355\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u904d\u5386\u5b57\u5178\u4e2d\u7684\u5217\u503c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4f9b\u9009\u62e9\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u3002\u5bf9\u4e8e\u4e00\u822c\u60c5\u51b5\uff0c\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u6216items()\u65b9\u6cd5\u662f\u6700\u4e3a\u5e38\u89c1\u548c\u76f4\u89c2\u7684\u9009\u62e9\u3002\u5982\u679c\u9700\u8981\u5904\u7406\u590d\u6742\u6570\u636e\u7ed3\u6784\u6216\u63d0\u5347\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528itertools\u6a21\u5757\u6216pandas\u5e93\u3002\u5bf9\u4e8e\u5d4c\u5957\u5b57\u5178\uff0c\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u904d\u5386\u6240\u6709\u5c42\u7ea7\u7684\u952e\u503c\u5bf9\u3002\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u5b57\u5178\u7684\u7279\u5b9a\u5217\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u7684\u952e\u6765\u63d0\u53d6\u7279\u5b9a\u5217\u7684\u503c\u3002\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f\u6216\u5faa\u73af\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u5178\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u5217\u8868\u5e76\u63d0\u53d6\u6bcf\u4e2a\u5b57\u5178\u4e2d\u7279\u5b9a\u952e\u7684\u503c\uff0c\u5f62\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u3002<\/p>\n<p><strong>\u904d\u5386\u5b57\u5178\u65f6\u5982\u4f55\u5904\u7406\u5d4c\u5957\u5b57\u5178\u7684\u503c\uff1f<\/strong><br \/>\u5bf9\u4e8e\u5d4c\u5957\u5b57\u5178\uff0c\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u6216\u5d4c\u5957\u5faa\u73af\u6765\u904d\u5386\u3002\u5728\u8bbf\u95ee\u5d4c\u5957\u5b57\u5178\u7684\u503c\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u6b63\u786e\u5f15\u7528\u6bcf\u4e00\u5c42\u7684\u952e\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u63d0\u53d6\u6df1\u5c42\u6b21\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u6765\u904d\u5386\u5b57\u5178\u7684\u5217\u503c\uff1f<\/strong><br \/>\u662f\u7684\uff0cPandas\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u5c06\u5b57\u5178\u8f6c\u6362\u4e3aDataFrame\uff0c\u65b9\u4fbf\u5730\u904d\u5386\u548c\u64cd\u4f5c\u5217\u503c\u3002\u4f7f\u7528DataFrame\u7684<code>apply<\/code>\u65b9\u6cd5\u6216\u76f4\u63a5\u7d22\u5f15\u5217\uff0c\u53ef\u4ee5\u8f7b\u677e\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u904d\u5386\u5b57\u5178\u4e2d\u5217\u7684\u503c\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u952e\u503c\u5bf9\u3001\u4f7f\u7528\u5b57\u5178\u7684keys()\u65b9\u6cd5\u3001\u4f7f\u7528\u5b57\u5178\u7684valu [&hellip;]","protected":false},"author":3,"featured_media":1036787,"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\/1036780"}],"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=1036780"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036780\/revisions"}],"predecessor-version":[{"id":1036789,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036780\/revisions\/1036789"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1036787"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1036780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1036780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1036780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}