{"id":1066000,"date":"2024-12-31T16:22:25","date_gmt":"2024-12-31T08:22:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1066000.html"},"modified":"2024-12-31T16:22:27","modified_gmt":"2024-12-31T08:22:27","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e7%9c%81%e5%b8%82%e5%8c%ba%e6%8b%86%e5%88%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1066000.html","title":{"rendered":"python\u5982\u4f55\u5c06\u7701\u5e02\u533a\u62c6\u5206"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/80adf56e-4c5d-4c7d-b142-73f059fbcf69.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u5c06\u7701\u5e02\u533a\u62c6\u5206\" \/><\/p>\n<p><p> <strong>Python\u5c06\u7701\u5e02\u533a\u62c6\u5206\u7684\u5e38\u89c1\u65b9\u6cd5\u6709\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u5206\u5272\u3001\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93<\/strong>\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u793a\u4f8b\uff0c\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\uff08Regular Expression\uff0c\u7b80\u79f0regex\uff09\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5b57\u7b26\u4e32\u5339\u914d\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u4ece\u590d\u6742\u7684\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7279\u5b9a\u6a21\u5f0f\u7684\u6587\u672c\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\uff0c\u5e76\u5c06\u5176\u62c6\u5206\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u5b9a\u4e49\u4e00\u7ec4\u89c4\u5219\uff0c\u6765\u63cf\u8ff0\u6587\u672c\u7684\u6a21\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u4e2d\u56fd\u7701\u5e02\u533a\u7684\u5e38\u89c1\u547d\u540d\u89c4\u5219\u6765\u7f16\u5199\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u7701\u5e02\u533a\u7684\u62c6\u5206\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>def split_address(address):<\/p>\n<p>    pattern = re.compile(r&#39;(.*?\u7701|.*?\u81ea\u6cbb\u533a|.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u5e02\u8f96\u533a|.*?\u5dde|.*?\u76df)(.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u5e02\u8f96\u533a|.*?\u65d7|.*?\u5dde|.*?\u76df)(.*)&#39;)<\/p>\n<p>    match = pattern.match(address)<\/p>\n<p>    if match:<\/p>\n<p>        return match.groups()<\/p>\n<p>    else:<\/p>\n<p>        return None<\/p>\n<p>address = &quot;\u56db\u5ddd\u7701\u6210\u90fd\u5e02\u6b66\u4faf\u533a&quot;<\/p>\n<p>result = split_address(address)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002\u7136\u540e\uff0c\u901a\u8fc7\u8c03\u7528<code>re.compile<\/code>\u51fd\u6570\u6765\u7f16\u8bd1\u8fd9\u4e2a\u6a21\u5f0f\uff0c\u5e76\u4f7f\u7528<code>pattern.match<\/code>\u65b9\u6cd5\u6765\u5339\u914d\u8f93\u5165\u5730\u5740\u3002\u6700\u540e\uff0c\u901a\u8fc7<code>match.groups()<\/code>\u65b9\u6cd5\u5c06\u5339\u914d\u7ed3\u679c\u8fd4\u56de\u3002<\/p>\n<\/p>\n<p><p><strong>\u5c55\u5f00\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5b83\u53ef\u4ee5\u7075\u6d3b\u5730\u5904\u7406\u4e0d\u540c\u683c\u5f0f\u7684\u5730\u5740\u3002\u4f8b\u5982\uff0c\u6709\u4e9b\u5730\u5740\u4e2d\u7701\u3001\u5e02\u3001\u533a\u7684\u987a\u5e8f\u53ef\u80fd\u4e0d\u540c\uff0c\u6216\u8005\u67d0\u4e9b\u5730\u5740\u4e2d\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u53ef\u80fd\u4f1a\u5305\u542b\u66f4\u591a\u7684\u4fee\u9970\u8bcd\u3002\u901a\u8fc7\u8c03\u6574\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5904\u7406\u8fd9\u4e9b\u4e0d\u540c\u7684\u60c5\u51b5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u6a21\u5f0f\uff0c\u4ee5\u5339\u914d\u53ef\u80fd\u5305\u542b\u7684\u4fee\u9970\u8bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def split_address(address):<\/p>\n<p>    pattern = re.compile(r&#39;(.*?\u7701|.*?\u81ea\u6cbb\u533a|.*?\u7279\u522b\u884c\u653f\u533a|.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u65d7|.*?\u5dde|.*?\u76df)(.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u65d7|.*?\u5dde|.*?\u76df|.*?\u7279\u522b\u884c\u653f\u533a|.*?\u8857\u9053|.*?\u4e61|.*?\u9547)(.*)&#39;)<\/p>\n<p>    match = pattern.match(address)<\/p>\n<p>    if match:<\/p>\n<p>        return match.groups()<\/p>\n<p>    else:<\/p>\n<p>        return None<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u79cd\u7c7b\u7684\u5730\u5740\u683c\u5f0f\uff0c\u786e\u4fdd\u62c6\u5206\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5b57\u7b26\u4e32\u5206\u5272<\/p>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u5206\u5272\u662f\u53e6\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u67e5\u627e\u7279\u5b9a\u7684\u5206\u9694\u7b26\uff08\u5982\u201c\u7701\u201d\u3001\u201c\u5e02\u201d\u3001\u201c\u533a\u201d\u7b49\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5730\u5740\u5b57\u7b26\u4e32\u8fdb\u884c\u5206\u5272\uff0c\u4ece\u800c\u5f97\u5230\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002\u8fd9\u79cd\u65b9\u6cd5\u76f8\u5bf9\u7b80\u5355\uff0c\u4f46\u9700\u8981\u5904\u7406\u4e0d\u540c\u7684\u5206\u9694\u7b26\u548c\u5730\u5740\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def split_address(address):<\/p>\n<p>    province_end = address.find(&#39;\u7701&#39;) + 1<\/p>\n<p>    city_end = address.find(&#39;\u5e02&#39;) + 1<\/p>\n<p>    district_end = address.find(&#39;\u533a&#39;) + 1<\/p>\n<p>    province = address[:province_end]<\/p>\n<p>    city = address[province_end:city_end]<\/p>\n<p>    district = address[city_end:district_end]<\/p>\n<p>    return province, city, district<\/p>\n<p>address = &quot;\u56db\u5ddd\u7701\u6210\u90fd\u5e02\u6b66\u4faf\u533a&quot;<\/p>\n<p>result = split_address(address)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u67e5\u627e\u201c\u7701\u201d\u3001\u201c\u5e02\u201d\u3001\u201c\u533a\u201d\u7684\u4f4d\u7f6e\uff0c\u5e76\u4f7f\u7528\u5b57\u7b26\u4e32\u5207\u7247\u6765\u5206\u5272\u5730\u5740\u5b57\u7b26\u4e32\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p><strong>\u5c55\u5f00\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u5206\u5272\u7684\u65b9\u6cd5\u867d\u7136\u7b80\u5355\uff0c\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u6709\u4e9b\u5730\u5740\u4e2d\u53ef\u80fd\u6ca1\u6709\u660e\u786e\u7684\u5206\u9694\u7b26\uff0c\u6216\u8005\u67d0\u4e9b\u5730\u5740\u7684\u683c\u5f0f\u53ef\u80fd\u4e0d\u540c\u3002\u4e3a\u4e86\u5904\u7406\u8fd9\u4e9b\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u66f4\u590d\u6742\u7684\u903b\u8f91\u6765\u67e5\u627e\u548c\u5206\u5272\u5730\u5740\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def split_address(address):<\/p>\n<p>    province_end = max(address.find(&#39;\u7701&#39;), address.find(&#39;\u81ea\u6cbb\u533a&#39;), address.find(&#39;\u7279\u522b\u884c\u653f\u533a&#39;)) + 1<\/p>\n<p>    city_end = max(address.find(&#39;\u5e02&#39;), address.find(&#39;\u533a&#39;), address.find(&#39;\u53bf&#39;), address.find(&#39;\u81ea\u6cbb\u53bf&#39;), address.find(&#39;\u65d7&#39;), address.find(&#39;\u5dde&#39;), address.find(&#39;\u76df&#39;)) + 1<\/p>\n<p>    district_end = max(address.find(&#39;\u533a&#39;), address.find(&#39;\u53bf&#39;), address.find(&#39;\u81ea\u6cbb\u53bf&#39;), address.find(&#39;\u65d7&#39;), address.find(&#39;\u8857\u9053&#39;), address.find(&#39;\u4e61&#39;), address.find(&#39;\u9547&#39;)) + 1<\/p>\n<p>    province = address[:province_end]<\/p>\n<p>    city = address[province_end:city_end]<\/p>\n<p>    district = address[city_end:district_end]<\/p>\n<p>    return province, city, district<\/p>\n<p>address = &quot;\u56db\u5ddd\u7701\u6210\u90fd\u5e02\u6b66\u4faf\u533a&quot;<\/p>\n<p>result = split_address(address)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u79cd\u7c7b\u7684\u5730\u5740\u683c\u5f0f\uff0c\u786e\u4fdd\u5206\u5272\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93<\/p>\n<\/p>\n<p><p>\u5730\u7406\u7f16\u7801\u5e93\u662f\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u5730\u7406\u4fe1\u606f\u7684\u5e93\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u52a0\u51c6\u786e\u548c\u5168\u9762\u7684\u5730\u7406\u4fe1\u606f\u89e3\u6790\u670d\u52a1\u3002\u5e38\u89c1\u7684\u5730\u7406\u7f16\u7801\u5e93\u5305\u62ec\u767e\u5ea6\u5730\u56feAPI\u3001\u9ad8\u5fb7\u5730\u56feAPI\u7b49\u3002\u901a\u8fc7\u8c03\u7528\u8fd9\u4e9bAPI\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5730\u5740\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a\u7701\u3001\u5e02\u3001\u533a\u7b49\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528\u9ad8\u5fb7\u5730\u56feAPI\u8fdb\u884c\u5730\u5740\u89e3\u6790\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>def get_location_det<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ls(address):<\/p>\n<p>    api_key = &#39;\u4f60\u7684\u9ad8\u5fb7\u5730\u56feAPI\u5bc6\u94a5&#39;<\/p>\n<p>    url = f&#39;https:\/\/restapi.amap.com\/v3\/geocode\/geo?address={address}&amp;key={api_key}&#39;<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    data = response.json()<\/p>\n<p>    if data[&#39;status&#39;] == &#39;1&#39; and data[&#39;geocodes&#39;]:<\/p>\n<p>        location = data[&#39;geocodes&#39;][0]<\/p>\n<p>        province = location[&#39;province&#39;]<\/p>\n<p>        city = location[&#39;city&#39;]<\/p>\n<p>        district = location[&#39;district&#39;]<\/p>\n<p>        return province, city, district<\/p>\n<p>    else:<\/p>\n<p>        return None<\/p>\n<p>address = &quot;\u56db\u5ddd\u7701\u6210\u90fd\u5e02\u6b66\u4faf\u533a&quot;<\/p>\n<p>result = get_location_details(address)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u5411\u9ad8\u5fb7\u5730\u56feAPI\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u5730\u5740\u7684\u8be6\u7ec6\u5730\u7406\u4fe1\u606f\u3002\u7136\u540e\uff0c\u901a\u8fc7\u89e3\u6790API\u8fd4\u56de\u7684JSON\u6570\u636e\uff0c\u63d0\u53d6\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p><strong>\u5c55\u5f00\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93\u7684\u4f18\u52bf\u5728\u4e8e\uff0c\u5b83\u53ef\u4ee5\u5904\u7406\u5404\u79cd\u590d\u6742\u7684\u5730\u5740\u683c\u5f0f\uff0c\u5e76\u63d0\u4f9b\u51c6\u786e\u7684\u5730\u7406\u4fe1\u606f\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93\u901a\u5e38\u9700\u8981API\u5bc6\u94a5\uff0c\u5e76\u4e14\u53ef\u80fd\u4f1a\u53d7\u5230API\u8c03\u7528\u6b21\u6570\u7684\u9650\u5236\u3002\u6b64\u5916\uff0c\u5730\u7406\u7f16\u7801\u5e93\u7684\u89e3\u6790\u7ed3\u679c\u4f9d\u8d56\u4e8e\u5176\u6570\u636e\u5e93\u7684\u51c6\u786e\u6027\u548c\u5168\u9762\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u786e\u4fdd\u66f4\u597d\u7684\u4f7f\u7528\u4f53\u9a8c\uff0c\u6211\u4eec\u53ef\u4ee5\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u6765\u5904\u7406\u5730\u5740\u89e3\u6790\u3002\u4f8b\u5982\uff0c\u5728\u5730\u7406\u7f16\u7801\u5e93\u89e3\u6790\u5931\u8d25\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u5b57\u7b26\u4e32\u5206\u5272\u7684\u65b9\u6cd5\u4f5c\u4e3a\u5907\u7528\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def split_address_fallback(address):<\/p>\n<p>    # \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4f5c\u4e3a\u5907\u7528\u65b9\u6848<\/p>\n<p>    pattern = re.compile(r&#39;(.*?\u7701|.*?\u81ea\u6cbb\u533a|.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u5e02\u8f96\u533a|.*?\u5dde|.*?\u76df)(.*?\u5e02|.*?\u533a|.*?\u53bf|.*?\u81ea\u6cbb\u53bf|.*?\u5e02\u8f96\u533a|.*?\u65d7|.*?\u5dde|.*?\u76df)(.*)&#39;)<\/p>\n<p>    match = pattern.match(address)<\/p>\n<p>    if match:<\/p>\n<p>        return match.groups()<\/p>\n<p>    else:<\/p>\n<p>        # \u4f7f\u7528\u5b57\u7b26\u4e32\u5206\u5272\u4f5c\u4e3a\u5907\u7528\u65b9\u6848<\/p>\n<p>        province_end = address.find(&#39;\u7701&#39;) + 1<\/p>\n<p>        city_end = address.find(&#39;\u5e02&#39;) + 1<\/p>\n<p>        district_end = address.find(&#39;\u533a&#39;) + 1<\/p>\n<p>        province = address[:province_end]<\/p>\n<p>        city = address[province_end:city_end]<\/p>\n<p>        district = address[city_end:district_end]<\/p>\n<p>        return province, city, district<\/p>\n<p>def get_location_details_with_fallback(address):<\/p>\n<p>    api_key = &#39;\u4f60\u7684\u9ad8\u5fb7\u5730\u56feAPI\u5bc6\u94a5&#39;<\/p>\n<p>    url = f&#39;https:\/\/restapi.amap.com\/v3\/geocode\/geo?address={address}&amp;key={api_key}&#39;<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    data = response.json()<\/p>\n<p>    if data[&#39;status&#39;] == &#39;1&#39; and data[&#39;geocodes&#39;]:<\/p>\n<p>        location = data[&#39;geocodes&#39;][0]<\/p>\n<p>        province = location[&#39;province&#39;]<\/p>\n<p>        city = location[&#39;city&#39;]<\/p>\n<p>        district = location[&#39;district&#39;]<\/p>\n<p>        return province, city, district<\/p>\n<p>    else:<\/p>\n<p>        return split_address_fallback(address)<\/p>\n<p>address = &quot;\u56db\u5ddd\u7701\u6210\u90fd\u5e02\u6b66\u4faf\u533a&quot;<\/p>\n<p>result = get_location_details_with_fallback(address)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u9ad8\u5730\u5740\u89e3\u6790\u7684\u6210\u529f\u7387\uff0c\u786e\u4fdd\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\u90fd\u80fd\u5f97\u5230\u51c6\u786e\u7684\u89e3\u6790\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u672c\u6587\u4ecb\u7ecd\u4e86\u4e09\u79cd\u5e38\u89c1\u7684Python\u5c06\u7701\u5e02\u533a\u62c6\u5206\u7684\u65b9\u6cd5\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u5206\u5272\u3001\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\uff1a\u9002\u7528\u4e8e\u5904\u7406\u590d\u6742\u7684\u5730\u5740\u683c\u5f0f\uff0c\u901a\u8fc7\u5b9a\u4e49\u5339\u914d\u6a21\u5f0f\uff0c\u53ef\u4ee5\u7075\u6d3b\u5730\u63d0\u53d6\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002\u7f3a\u70b9\u662f\u7f16\u5199\u548c\u8c03\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u6bd4\u8f83\u590d\u6742\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b57\u7b26\u4e32\u5206\u5272<\/strong>\uff1a\u9002\u7528\u4e8e\u7b80\u5355\u7684\u5730\u5740\u683c\u5f0f\uff0c\u901a\u8fc7\u67e5\u627e\u7279\u5b9a\u7684\u5206\u9694\u7b26\uff0c\u8fdb\u884c\u5b57\u7b26\u4e32\u5207\u7247\u3002\u7f3a\u70b9\u662f\u9700\u8981\u5904\u7406\u4e0d\u540c\u7684\u5206\u9694\u7b26\u548c\u5730\u5740\u683c\u5f0f\uff0c\u53ef\u80fd\u4e0d\u591f\u7075\u6d3b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93<\/strong>\uff1a\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u51c6\u786e\u6027\u7684\u5730\u5740\u89e3\u6790\uff0c\u901a\u8fc7\u8c03\u7528\u5730\u7406\u7f16\u7801API\uff0c\u53ef\u4ee5\u83b7\u53d6\u8be6\u7ec6\u7684\u5730\u7406\u4fe1\u606f\u3002\u7f3a\u70b9\u662f\u4f9d\u8d56\u4e8eAPI\u7684\u7a33\u5b9a\u6027\u548c\u6570\u636e\u5e93\u7684\u51c6\u786e\u6027\uff0c\u5e76\u4e14\u53ef\u80fd\u53d7\u5230API\u8c03\u7528\u6b21\u6570\u7684\u9650\u5236\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u6848\u3002\u4f8b\u5982\uff0c\u5728\u9ad8\u5fb7\u5730\u56feAPI\u89e3\u6790\u5931\u8d25\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u5b57\u7b26\u4e32\u5206\u5272\u7684\u65b9\u6cd5\u4f5c\u4e3a\u5907\u7528\u65b9\u6848\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5730\u5740\u89e3\u6790\u7684\u6210\u529f\u7387\uff0c\u786e\u4fdd\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\u90fd\u80fd\u5f97\u5230\u51c6\u786e\u7684\u89e3\u6790\u7ed3\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u7701\u5e02\u533a\u7684\u4fe1\u606f\u8fdb\u884c\u62c6\u5206\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5206\u5272\u65b9\u6cd5\u6765\u62c6\u5206\u7701\u5e02\u533a\u7684\u4fe1\u606f\u3002\u901a\u5e38\uff0c\u7701\u3001\u5e02\u3001\u533a\u7684\u4fe1\u606f\u4f1a\u4ee5\u67d0\u79cd\u5206\u9694\u7b26\uff08\u5982\u9017\u53f7\u6216\u7a7a\u683c\uff09\u8fde\u63a5\u5728\u4e00\u8d77\u3002\u53ef\u4ee5\u4f7f\u7528<code>split()<\/code>\u65b9\u6cd5\u5c06\u5176\u62c6\u5206\u4e3a\u5355\u72ec\u7684\u90e8\u5206\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32<code>&quot;\u7701,\u5e02,\u533a&quot;<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>split(&#39;,&#39;)<\/code>\u6765\u83b7\u53d6\u4e00\u4e2a\u5217\u8868\uff0c\u5305\u542b\u7701\u3001\u5e02\u3001\u533a\u7684\u540d\u79f0\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u63a8\u8350\u7684\u5e93\u6765\u5904\u7406\u7701\u5e02\u533a\u6570\u636e\u7684\u62c6\u5206\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5730\u7406\u4fe1\u606f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\u3002\u901a\u8fc7\u5c06\u7701\u5e02\u533a\u7684\u6570\u636e\u5b58\u50a8\u5728DataFrame\u4e2d\uff0c\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u62c6\u5206\u548c\u5206\u6790\u3002<code>pandas<\/code>\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5904\u7406\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982<code>str.split()<\/code>\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u62c6\u5206\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u4e0d\u89c4\u5219\u7684\u7701\u5e02\u533a\u6570\u636e\uff1f<\/strong><br \/>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7701\u5e02\u533a\u7684\u6570\u636e\u53ef\u80fd\u5e76\u4e0d\u89c4\u8303\uff0c\u4f8b\u5982\u591a\u4f59\u7684\u7a7a\u683c\u6216\u7f3a\u5c11\u67d0\u4e9b\u90e8\u5206\u3002\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff08<code>re<\/code>\u6a21\u5757\uff09\u6765\u5339\u914d\u548c\u6e05\u6d17\u8fd9\u4e9b\u6570\u636e\u3002\u901a\u8fc7\u7f16\u5199\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u8bc6\u522b\u5e76\u63d0\u53d6\u51fa\u7701\u3001\u5e02\u3001\u533a\u7684\u4fe1\u606f\uff0c\u5373\u4f7f\u5b83\u4eec\u7684\u683c\u5f0f\u6709\u6240\u4e0d\u540c\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u5728\u62c6\u5206\u540e\u4ecd\u7136\u51c6\u786e\u65e0\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5c06\u7701\u5e02\u533a\u62c6\u5206\u7684\u5e38\u89c1\u65b9\u6cd5\u6709\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u5206\u5272\u3001\u4f7f\u7528\u5730\u7406\u7f16\u7801\u5e93\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b [&hellip;]","protected":false},"author":3,"featured_media":1066008,"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\/1066000"}],"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=1066000"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066000\/revisions"}],"predecessor-version":[{"id":1066013,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066000\/revisions\/1066013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1066008"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1066000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1066000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1066000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}