{"id":45603,"date":"2020-11-02T20:36:12","date_gmt":"2020-11-02T12:36:12","guid":{"rendered":"http:\/\/www.zhushiyao.com\/?p=45603"},"modified":"2020-11-02T20:37:04","modified_gmt":"2020-11-02T12:37:04","slug":"e53b653405","status":"publish","type":"post","link":"http:\/\/www.zhushiyao.com\/?p=45603","title":{"rendered":"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy"},"content":{"rendered":"<div class=\"bpp-post-content\">\n<blockquote style=\"white-space: normal;\"><p><span style=\"font-size: 14px;\">\u6765\u6e90\uff1aBe_melting<\/span><\/p>\n<p><span style=\"font-size: 14px;\">blog.csdn.net\/lys_828\/article\/details\/106489371<\/span><\/p><\/blockquote>\n<h1 style=\"margin-bottom: 16px; font-size: 18px; white-space: normal; box-sizing: border-box; outline: 0px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: left; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u3010\u5bfc\u8bed\u3011\uff1a\u8fd8\u5728\u4e3a\u65e5\u5e38\u5de5\u4f5c\u4e2d\u4e0d\u540c\u7684\u6570\u636e\u96c6\u7684\u5b57\u6bb5\u8fdb\u884c\u5339\u914d\u70e6\u607c\uff1f\u4eca\u5929\u8ddf\u5927\u5bb6\u5206\u4eabFuzzyWuzzy\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684\u6a21\u7cca\u5b57\u7b26\u4e32\u5339\u914d\u5de5\u5177\u5305\u3002\u8ba9\u4f60\u591a\u5feb\u597d\u7701\u7684\u89e3\u51b3\u70e6\u607c\u7684\u5339\u914d\u95ee\u9898\uff01<\/span><\/h1>\n<h1 style=\"margin-bottom: 16px; font-size: 18px; white-space: normal; box-sizing: border-box; outline: 0px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: center; background-color: #ffffff;\"><span style=\"font-size: 15px; color: #ff6827;\"><strong>1. \u524d\u8a00<\/strong><\/span><\/h1>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u5728\u5904\u7406\u6570\u636e\u7684\u8fc7\u7a0b\u4e2d\uff0c\u96be\u514d\u4f1a\u9047\u5230\u4e0b\u9762\u7c7b\u4f3c\u7684\u573a\u666f\uff0c\u81ea\u5df1\u624b\u91cc\u5934\u83b7\u5f97\u7684\u662f\u7b80\u5316\u7248\u7684\u6570\u636e\u5b57\u6bb5\uff0c\u4f46\u662f\u8981\u6bd4\u5bf9\u7684\u6216\u8005\u8981\u5408\u5e76\u7684\u5374\u662f\u5b8c\u6574\u7248\u7684\u6570\u636e\uff08\u6709\u65f6\u5019\u4e5f\u4f1a\u53cd\u8fc7\u6765\uff09<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u6700\u5e38\u89c1\u7684\u4e00\u4e2a\u4f8b\u5b50\u5c31\u662f\uff1a\u5728\u8fdb\u884c\u5730\u7406\u53ef\u89c6\u5316\u4e2d\uff0c\u81ea\u5df1\u6536\u96c6\u7684\u6570\u636e\u53ea\u4fdd\u7559\u7684\u7f29\u5199\uff0c\u6bd4\u5982\u5317\u4eac\uff0c\u5e7f\u897f\uff0c\u65b0\u7586\uff0c\u897f\u85cf\u7b49\uff0c\u4f46\u662f\u5f85\u5339\u914d\u7684\u5b57\u6bb5\u6570\u636e\u5374\u662f\u5317\u4eac\u5e02\uff0c\u5e7f\u897f\u58ee\u65cf\u81ea\u6cbb\u533a\uff0c\u65b0\u7586\u7ef4\u543e\u5c14\u81ea\u6cbb\u533a\uff0c\u897f\u85cf\u81ea\u6cbb\u533a\u7b49\uff0c\u5982\u4e0b\u3002\u56e0\u6b64\u5c31\u9700\u8981\u6709\u6ca1\u6709\u4e00\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5f88\u5feb\u901f\u4fbf\u6377\u7684\u76f4\u63a5\u8fdb\u884c\u5bf9\u5e94\u5b57\u6bb5\u7684\u5339\u914d\u5e76\u5c06\u7ed3\u679c\u5355\u72ec\u751f\u6210\u4e00\u5217\uff0c\u5c31\u53ef\u4ee5\u7528\u5230FuzzyWuzzy\u5e93\u3002<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\"><img decoding=\"async\" title=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/11\/2-1604320572.png\" alt=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" \/><\/span><\/p>\n<h1 style=\"white-space: normal; text-align: center;\"><\/h1>\n<h1 style=\"white-space: normal; text-align: center;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2. FuzzyWuzzy\u5e93\u4ecb\u7ecd<\/span><\/strong><\/span><\/h1>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">FuzzyWuzzy \u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684\u6a21\u7cca\u5b57\u7b26\u4e32\u5339\u914d\u5de5\u5177\u5305\u3002\u5b83\u4f9d\u636e\u00a0<\/span><span style=\"font-size: 15px;\">Levenshtein Distance \u7b97\u6cd5\uff0c<\/span><span style=\"font-size: 15px;\">\u8ba1\u7b97\u4e24\u4e2a\u5e8f\u5217\u4e4b\u95f4\u7684\u5dee\u5f02\u3002<\/span><\/p>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px; background-color: #fffed5;\">Levenshtein Distance<\/span><span style=\"font-size: 15px;\">\u7b97\u6cd5\uff0c\u53c8\u53eb<\/span><span style=\"font-size: 15px; background-color: #fffed5;\">\u00a0Edit Distance<\/span><span style=\"font-size: 15px;\">\u7b97\u6cd5\uff0c\u662f\u6307\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\uff0c\u7531\u4e00\u4e2a\u8f6c\u6210\u53e6\u4e00\u4e2a\u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u64cd\u4f5c\u6b21\u6570\u3002\u8bb8\u53ef\u7684\u7f16\u8f91\u64cd\u4f5c\u5305\u62ec\u5c06\u4e00\u4e2a\u5b57\u7b26\u66ff\u6362\u6210\u53e6\u4e00\u4e2a\u5b57\u7b26\uff0c\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\uff0c\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7f16\u8f91\u8ddd\u79bb\u8d8a\u5c0f\uff0c\u4e24\u4e2a\u4e32\u7684\u76f8\u4f3c\u5ea6\u8d8a\u5927\u3002<\/span><\/p>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u8fd9\u91cc\u4f7f\u7528\u7684\u662fAnaconda\u4e0b\u7684jupyter notebook\u7f16\u7a0b\u73af\u5883\uff0c\u56e0\u6b64\u5728Anaconda\u7684\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4e00\u4e0b\u6307\u4ee4\u8fdb\u884c\u7b2c\u4e09\u65b9\u5e93\u5b89\u88c5\u3002<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">pip\u00a0install\u00a0-i\u00a0https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\u00a0FuzzyWuzzy<\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<h2 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.1 fuzz\u6a21\u5757<\/span><\/strong><\/span><\/h2>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u8be5\u6a21\u5757\u4e0b\u4e3b\u8981\u4ecb\u7ecd\u56db\u4e2a\u51fd\u6570\uff08\u65b9\u6cd5\uff09\uff0c\u5206\u522b\u4e3a\uff1a\u7b80\u5355\u5339\u914d\uff08Ratio\uff09\u3001\u975e\u5b8c\u5168\u5339\u914d\uff08Partial Ratio\uff09\u3001\u5ffd\u7565\u987a\u5e8f\u5339\u914d\uff08Token Sort Ratio\uff09\u548c\u53bb\u91cd\u5b50\u96c6\u5339\u914d\uff08Token Set Ratio\uff09<\/span><\/p>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u6ce8\u610f\uff1a\u00a0\u5982\u679c\u76f4\u63a5\u5bfc\u5165\u8fd9\u4e2a\u6a21\u5757\u7684\u8bdd\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793awarning\uff0c\u5f53\u7136\u8fd9\u4e0d\u4ee3\u8868\u62a5\u9519\uff0c\u7a0b\u5e8f\u4f9d\u65e7\u53ef\u4ee5\u8fd0\u884c\uff08\u4f7f\u7528\u7684\u9ed8\u8ba4\u7b97\u6cd5\uff0c\u6267\u884c\u901f\u5ea6\u8f83\u6162\uff09\uff0c\u53ef\u4ee5\u6309\u7167\u7cfb\u7edf\u7684\u63d0\u793a\u5b89\u88c5python-Levenshtein\u5e93\u8fdb\u884c\u8f85\u52a9\uff0c\u8fd9\u6709\u5229\u4e8e\u63d0\u9ad8\u8ba1\u7b97\u7684\u901f\u5ea6\u3002<\/span><\/p>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\"><img decoding=\"async\" title=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/11\/3-1604320572.png\" alt=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" \/><\/span><\/p>\n<p style=\"white-space: normal;\">\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.1.1 \u7b80\u5355\u5339\u914d\uff08Ratio\uff09<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u7b80\u5355\u7684\u4e86\u89e3\u4e00\u4e0b\u5c31\u884c\uff0c\u8fd9\u4e2a\u4e0d\u600e\u4e48\u7cbe\u786e\uff0c\u4e5f\u4e0d\u5e38\u7528<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">fuzz.ratio(<span class=\"code-snippet__string\">\"\u6cb3\u5357\u7701\"<\/span>, <span class=\"code-snippet__string\">\"\u6cb3\u5357\u7701\"<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; <span class=\"code-snippet__number\">100<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">&gt;<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.ratio(<span class=\"code-snippet__string\">\"\u6cb3\u5357\"<\/span>, <span class=\"code-snippet__string\">\"\u6cb3\u5357\u7701\"<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; <span class=\"code-snippet__number\">80<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><\/pre>\n<\/section>\n<h3 style=\"white-space: normal;\"><\/h3>\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.1.2 \u975e\u5b8c\u5168\u5339\u914d\uff08Partial Ratio\uff09<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u5c3d\u91cf\u4f7f\u7528\u975e\u5b8c\u5168\u5339\u914d\uff0c\u7cbe\u5ea6\u8f83\u9ad8<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">fuzz.partial_ratio(\"\u6cb3\u5357\u7701\", \"\u6cb3\u5357\u7701\")<\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt; 100<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.partial_ratio(\"\u6cb3\u5357\", \"\u6cb3\u5357\u7701\")<\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt; 100<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.1.3 \u5ffd\u7565\u987a\u5e8f\u5339\u914d\uff08Token Sort Ratio\uff09<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u539f\u7406\u5728\u4e8e\uff1a\u4ee5\u00a0\u7a7a\u683c\u00a0\u4e3a\u5206\u9694\u7b26\uff0c\u5c0f\u5199\u00a0\u5316\u6240\u6709\u5b57\u6bcd\uff0c\u65e0\u89c6\u7a7a\u683c\u5916\u7684\u5176\u5b83\u6807\u70b9\u7b26\u53f7<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">fuzz.ratio(\"\u897f\u85cf \u81ea\u6cbb\u533a\", \"\u81ea\u6cbb\u533a \u897f\u85cf\")<\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt; 50<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.ratio('I love YOU','YOU LOVE I')<\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt; 30<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.token_sort_ratio(\"\u897f\u85cf \u81ea\u6cbb\u533a\", \"\u81ea\u6cbb\u533a \u897f\u85cf\") <\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt; 100<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.token_sort_ratio('I love YOU','YOU LOVE I') <\/span><\/code><code><span class=\"code-snippet_outer\">&gt;&gt;&gt;\u00a0100<\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.1.4 \u53bb\u91cd\u5b50\u96c6\u5339\u914d\uff08Token Set Ratio\uff09<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u76f8\u5f53\u4e8e\u6bd4\u5bf9\u4e4b\u524d\u6709\u4e00\u4e2a\u96c6\u5408\u53bb\u91cd\u7684\u8fc7\u7a0b\uff0c\u6ce8\u610f\u6700\u540e\u4e24\u4e2a\uff0c\u53ef\u7406\u89e3\u4e3a\u8be5\u65b9\u6cd5\u662f\u5728token_sort_ratio\u65b9\u6cd5\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e86\u96c6\u5408\u53bb\u91cd\u7684\u529f\u80fd\uff0c\u4e0b\u9762\u4e09\u4e2a\u5339\u914d\u7684\u90fd\u662f\u5012\u5e8f<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">fuzz.ratio(<span class=\"code-snippet__string\">\"\u897f\u85cf \u897f\u85cf \u81ea\u6cbb\u533a\"<\/span>, <span class=\"code-snippet__string\">\"\u81ea\u6cbb\u533a \u897f\u85cf\"<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; <span class=\"code-snippet__number\">40<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.token_sort_ratio(<span class=\"code-snippet__string\">\"\u897f\u85cf \u897f\u85cf \u81ea\u6cbb\u533a\"<\/span>, <span class=\"code-snippet__string\">\"\u81ea\u6cbb\u533a \u897f\u85cf\"<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; <span class=\"code-snippet__number\">80<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">fuzz.token_set_ratio(<span class=\"code-snippet__string\">\"\u897f\u85cf \u897f\u85cf \u81ea\u6cbb\u533a\"<\/span>, <span class=\"code-snippet__string\">\"\u81ea\u6cbb\u533a \u897f\u85cf\"<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt;\u00a0<span class=\"code-snippet__number\">100<\/span><\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">fuzz\u8fd9\u51e0\u4e2aratio()\u51fd\u6570\uff08\u65b9\u6cd5\uff09\u6700\u540e\u5f97\u5230\u7684\u7ed3\u679c\u90fd\u662f\u6570\u5b57\uff0c\u5982\u679c\u9700\u8981\u83b7\u5f97\u5339\u914d\u5ea6\u6700\u9ad8\u7684\u5b57\u7b26\u4e32\u7ed3\u679c\uff0c\u8fd8\u9700\u8981\u4f9d\u65e7\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b\u9009\u62e9\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u7136\u540e\u518d\u8fdb\u884c\u7ed3\u679c\u63d0\u53d6\uff0c\u5982\u679c\u4f46\u770b\u6587\u672c\u6570\u636e\u7684\u5339\u914d\u7a0b\u5ea6\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u662f\u53ef\u4ee5\u91cf\u5316\u7684\uff0c\u4f46\u662f\u5bf9\u4e8e\u6211\u4eec\u8981\u63d0\u53d6\u5339\u914d\u7684\u7ed3\u679c\u6765\u8bf4\u5c31\u4e0d\u662f\u5f88\u65b9\u4fbf\u4e86\uff0c\u56e0\u6b64\u5c31\u6709\u4e86process\u6a21\u5757\u3002<\/span><\/p>\n<p style=\"white-space: normal;\">\n<h2 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.2 process\u6a21\u5757<\/span><\/strong><\/span><\/h2>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u7528\u4e8e\u5904\u7406\u5907\u9009\u7b54\u6848\u6709\u9650\u7684\u60c5\u51b5\uff0c\u8fd4\u56de\u6a21\u7cca\u5339\u914d\u7684\u5b57\u7b26\u4e32\u548c\u76f8\u4f3c\u5ea6\u3002<\/span><\/p>\n<p style=\"white-space: normal;\">\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.2.1 extract\u63d0\u53d6\u591a\u6761\u6570\u636e<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u7c7b\u4f3c\u4e8e\u722c\u866b\u4e2dselect\uff0c\u8fd4\u56de\u7684\u662f\u5217\u8868\uff0c\u5176\u4e2d\u4f1a\u5305\u542b\u5f88\u591a\u5339\u914d\u7684\u6570\u636e<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">choices = [<span class=\"code-snippet__string\">\"\u6cb3\u5357\u7701\"<\/span>, <span class=\"code-snippet__string\">\"\u90d1\u5dde\u5e02\"<\/span>, <span class=\"code-snippet__string\">\"\u6e56\u5317\u7701\"<\/span>, <span class=\"code-snippet__string\">\"\u6b66\u6c49\u5e02\"<\/span>]<\/span><\/code><code><span class=\"code-snippet_outer\">process.extract(<span class=\"code-snippet__string\">\"\u90d1\u5dde\"<\/span>, choices, limit=<span class=\"code-snippet__number\">2<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; [(<span class=\"code-snippet__string\">'\u90d1\u5dde\u5e02'<\/span>, <span class=\"code-snippet__number\">90<\/span>), (<span class=\"code-snippet__string\">'\u6cb3\u5357\u7701'<\/span>, <span class=\"code-snippet__number\">0<\/span>)]<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">#\u00a0extract\u4e4b\u540e\u7684\u6570\u636e\u7c7b\u578b\u662f\u5217\u8868\uff0c\u5373\u4f7flimit=1\uff0c\u6700\u540e\u8fd8\u662f\u5217\u8868\uff0c\u6ce8\u610f\u548c\u4e0b\u9762extractOne\u7684\u533a\u522b<\/span><\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">2.2.2 extractOne\u63d0\u53d6\u4e00\u6761\u6570\u636e<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u5982\u679c\u8981\u63d0\u53d6\u5339\u914d\u5ea6\u6700\u5927\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528extractOne\uff0c\u6ce8\u610f\u8fd9\u91cc\u8fd4\u56de\u7684\u662f\u00a0\u5143\u7ec4\u00a0\u7c7b\u578b\uff0c \u8fd8\u6709\u5c31\u662f\u5339\u914d\u5ea6\u6700\u5927\u7684\u7ed3\u679c\u4e0d\u4e00\u5b9a\u662f\u6211\u4eec\u60f3\u8981\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u793a\u4f8b\u548c\u4e24\u4e2a\u5b9e\u6218\u5e94\u7528\u4f53\u4f1a\u4e00\u4e0b<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">process.extractOne(<span class=\"code-snippet__string\">\"\u90d1\u5dde\"<\/span>, choices)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt; (<span class=\"code-snippet__string\">'\u90d1\u5dde\u5e02'<\/span>, <span class=\"code-snippet__number\">90<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">process.extractOne(<span class=\"code-snippet__string\">\"\u5317\u4eac\"<\/span>, choices)<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__meta\">&gt;&gt;<\/span>&gt;\u00a0(<span class=\"code-snippet__string\">'\u6e56\u5317\u7701'<\/span>,\u00a0<span class=\"code-snippet__number\">45<\/span>)<\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\n<h1 style=\"white-space: normal; text-align: center;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">3. \u5b9e\u6218\u5e94\u7528<\/span><\/strong><\/span><\/h1>\n<p style=\"white-space: normal;\">\n<p style=\"white-space: normal;\"><span style=\"font-size: 15px;\">\u8fd9\u91cc\u4e3e\u4e24\u4e2a\u5b9e\u6218\u5e94\u7528\u7684\u5c0f\u4f8b\u5b50\uff0c\u7b2c\u4e00\u4e2a\u662f\u516c\u53f8\u540d\u79f0\u5b57\u6bb5\u7684\u6a21\u7cca\u5339\u914d\uff0c\u7b2c\u4e8c\u4e2a\u662f\u7701\u5e02\u5b57\u6bb5\u7684\u6a21\u7cca\u5339\u914d<\/span><\/p>\n<p style=\"white-space: normal;\">\n<h2 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">3.1 \u516c\u53f8\u540d\u79f0\u5b57\u6bb5\u6a21\u7cca\u5339\u914d<\/span><\/strong><\/span><\/h2>\n<p style=\"white-space: normal;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u6570\u636e\u53ca\u5f85\u5339\u914d\u7684\u6570\u636e\u6837\u5f0f\u5982\u4e0b\uff1a\u81ea\u5df1\u83b7\u53d6\u5230\u7684\u6570\u636e\u5b57\u6bb5\u7684\u540d\u79f0\u5f88\u7b80\u6d01\uff0c\u5e76\u4e0d\u662f\u516c\u53f8\u7684\u5168\u79f0\uff0c\u56e0\u6b64\u9700\u8981\u8fdb\u884c\u4e24\u4e2a\u5b57\u6bb5\u7684\u5408\u5e76<\/span><img decoding=\"async\" style=\"margin-top: 24px; margin-bottom: 24px; box-sizing: border-box; outline: none; overflow-wrap: break-word; cursor: zoom-in; border: 0px none initial;\" title=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/11\/6-1604320572.png\" alt=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" \/><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u76f4\u63a5\u5c06\u4ee3\u7801\u5c01\u88c5\u4e3a\u51fd\u6570\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u65b9\u4fbf\u65e5\u540e\u7684\u8c03\u7528\uff0c\u8fd9\u91cc\u53c2\u6570\u8bbe\u7f6e\u7684\u6bd4\u8f83\u8be6\u7ec6\uff0c\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/span><img decoding=\"async\" style=\"margin-top: 24px; margin-bottom: 24px; box-sizing: border-box; outline: none; overflow-wrap: break-word; cursor: zoom-in; border: 0px none initial;\" title=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/11\/5-1604320572.png\" alt=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" \/><\/p>\n<h3 style=\"margin-bottom: 16px; font-size: 18px; white-space: normal; box-sizing: border-box; outline: 0px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><\/h3>\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">3.1.1 \u53c2\u6570\u8bb2\u89e3\uff1a<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2460 \u7b2c\u4e00\u4e2a\u53c2\u6570df_1\u662f\u81ea\u5df1\u83b7\u53d6\u7684\u6b32\u5408\u5e76\u7684\u5de6\u4fa7\u6570\u636e\uff08\u8fd9\u91cc\u662fdata\u53d8\u91cf\uff09\uff1b<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2461 \u7b2c\u4e8c\u4e2a\u53c2\u6570df_2\u662f\u5f85\u5339\u914d\u7684\u6b32\u5408\u5e76\u7684\u53f3\u4fa7\u6570\u636e\uff08\u8fd9\u91cc\u662fcompany\u53d8\u91cf\uff09\uff1b<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2462 \u7b2c\u4e09\u4e2a\u53c2\u6570key1\u662fdf_1\u4e2d\u8981\u5904\u7406\u7684\u5b57\u6bb5\u540d\u79f0\uff08\u8fd9\u91cc\u662fdata\u53d8\u91cf\u91cc\u7684\u2018\u516c\u53f8\u540d\u79f0\u2019\u5b57\u6bb5\uff09<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2463 \u7b2c\u56db\u4e2a\u53c2\u6570key2\u662fdf_2\u4e2d\u8981\u5339\u914d\u7684\u5b57\u6bb5\u540d\u79f0\uff08\u8fd9\u91cc\u662fcompany\u53d8\u91cf\u91cc\u7684\u2018\u516c\u53f8\u540d\u79f0\u2019\u5b57\u6bb5\uff09<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2464 \u7b2c\u4e94\u4e2a\u53c2\u6570threshold\u662f\u8bbe\u5b9a\u63d0\u53d6\u7ed3\u679c\u5339\u914d\u5ea6\u7684\u6807\u51c6\u3002\u6ce8\u610f\u8fd9\u91cc\u5c31\u662f\u5bf9extractOne\u65b9\u6cd5\u7684\u5b8c\u5584\uff0c\u63d0\u53d6\u5230\u7684\u6700\u5927\u5339\u914d\u5ea6\u7684\u7ed3\u679c\u5e76\u4e0d\u4e00\u5b9a\u662f\u6211\u4eec\u9700\u8981\u7684\uff0c\u6240\u4ee5\u9700\u8981\u8bbe\u5b9a\u4e00\u4e2a\u9608\u503c\u6765\u8bc4\u5224\uff0c\u8fd9\u4e2a\u503c\u5c31\u4e3a90\uff0c\u53ea\u6709\u662f\u5927\u4e8e\u7b49\u4e8e90\uff0c\u8fd9\u4e2a\u5339\u914d\u7ed3\u679c\u6211\u4eec\u624d\u53ef\u4ee5\u63a5\u53d7<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2465 \u7b2c\u516d\u4e2a\u53c2\u6570\uff0c\u9ed8\u8ba4\u53c2\u6570\u5c31\u662f\u53ea\u8fd4\u56de\u4e24\u4e2a\u5339\u914d\u6210\u529f\u7684\u7ed3\u679c<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2466 \u8fd4\u56de\u503c\uff1a\u4e3adf_1\u6dfb\u52a0\u2018matches\u2019\u5b57\u6bb5\u540e\u7684\u65b0\u7684DataFrame\u6570\u636e<\/span><\/p>\n<h3 style=\"white-space: normal;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">3.1.2 \u6838\u5fc3\u4ee3\u7801\u8bb2\u89e3<\/span><\/strong><\/span><\/h3>\n<p style=\"white-space: normal;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u7b2c\u4e00\u90e8\u5206\u4ee3\u7801\u5982\u4e0b\uff0c\u53ef\u4ee5\u53c2\u8003\u4e0a\u9762\u8bb2\u89e3process.extract\u65b9\u6cd5\uff0c\u8fd9\u91cc\u5c31\u662f\u76f4\u63a5\u4f7f\u7528\uff0c\u6240\u4ee5\u8fd4\u56de\u7684\u7ed3\u679cm\u5c31\u662f\u5217\u8868\u4e2d\u5d4c\u5957\u5143\u7956\u7684\u6570\u636e\u683c\u5f0f\uff0c\u6837\u5f0f\u4e3a: [(\u2018\u90d1\u5dde\u5e02\u2019, 90), (\u2018\u6cb3\u5357\u7701\u2019, 0)]\uff0c\u56e0\u6b64\u7b2c\u4e00\u6b21\u5199\u5165\u5230\u2019matches\u2019\u5b57\u6bb5\u4e2d\u7684\u6570\u636e\u4e5f\u5c31\u662f\u8fd9\u79cd\u683c\u5f0f<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u6ce8\u610f\uff0c\u6ce8\u610f\uff1a\u00a0\u5143\u7956\u4e2d\u7684\u7b2c\u4e00\u4e2a\u662f\u5339\u914d\u6210\u529f\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u5c31\u662f\u8bbe\u7f6e\u7684threshold\u53c2\u6570\u6bd4\u5bf9\u7684\u6570\u5b57\u5bf9\u8c61<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">s = df_2[key2].tolist()<\/span><\/code><code><span class=\"code-snippet_outer\">m = df_1[key1].apply(lambda x: process.extract(x, s, limit=limit))    <\/span><\/code><code><span class=\"code-snippet_outer\">df_1['matches']\u00a0=\u00a0m<\/span><\/code><\/pre>\n<\/section>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u7b2c\u4e8c\u90e8\u5206\u7684\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\uff0c\u6709\u4e86\u4e0a\u9762\u7684\u68b3\u7406\uff0c\u660e\u786e\u4e86\u2018matches\u2019\u5b57\u6bb5\u4e2d\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7136\u540e\u5c31\u662f\u8fdb\u884c\u6570\u636e\u7684\u63d0\u53d6\u4e86\uff0c\u9700\u8981\u5904\u7406\u7684\u90e8\u5206\u6709\u4e24\u70b9\u9700\u8981\u6ce8\u610f\u7684\uff1a<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2460 \u63d0\u53d6\u5339\u914d\u6210\u529f\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5bf9\u9608\u503c\u5c0f\u4e8e90\u7684\u6570\u636e\u586b\u5145\u7a7a\u503c<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u2461 \u6700\u540e\u628a\u6570\u636e\u6dfb\u52a0\u5230\u2018matches\u2019\u5b57\u6bb5<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\">m2 = df_1[<span class=\"code-snippet__string\">'matches'<\/span>].apply(lambda x: [<span class=\"code-snippet__string\">i[0<\/span>] for i in x if i[<span class=\"code-snippet__string\">1<\/span>] &gt;= threshold][0] if len([i[0] for i in x if i[1] &gt;= threshold]) &gt; 0 else '')<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__section\">#\u8981\u7406\u89e3\u7b2c\u4e00\u4e2a\u2018matches\u2019\u5b57\u6bb5\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u662f\u4ec0\u4e48\u6837\u5b50\u7684\uff0c\u5c31\u4e0d\u96be\u7406\u89e3\u8fd9\u884c\u4ee3\u7801\u4e86<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__section\">#\u53c2\u8003\u4e00\u4e0b\u8fd9\u4e2a\u683c\u5f0f\uff1a[('\u90d1\u5dde\u5e02', 90), ('\u6cb3\u5357\u7701', 0)]<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">df_1['matches'] = m2<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">return\u00a0df_1<\/span><\/code><\/pre>\n<\/section>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">3.2 \u7701\u4efd\u5b57\u6bb5\u6a21\u7cca\u5339\u914d<\/span><\/strong><\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u81ea\u5df1\u7684\u6570\u636e\u548c\u5f85\u5339\u914d\u7684\u6570\u636e\u80cc\u666f\u4ecb\u7ecd\u4e2d\u5df2\u7ecf\u6709\u56fe\u7247\u663e\u793a\u4e86\uff0c\u4e0a\u9762\u4e5f\u5df2\u7ecf\u5c01\u88c5\u4e86\u6a21\u7cca\u5339\u914d\u7684\u51fd\u6570\uff0c\u8fd9\u91cc\u76f4\u63a5\u8c03\u7528\u4e0a\u9762\u7684\u51fd\u6570\uff0c\u8f93\u5165\u76f8\u5e94\u7684\u53c2\u6570\u5373\u53ef\uff0c\u4ee3\u7801\u4ee5\u53ca\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/span><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><img decoding=\"async\" style=\"margin-top: 24px; margin-bottom: 24px; box-sizing: border-box; outline: none; overflow-wrap: break-word; cursor: zoom-in; border: 0px none initial;\" title=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/11\/8-1604320572.png\" alt=\"GitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\" \/><\/p>\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\">\n<p style=\"margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: start; background-color: #ffffff;\"><span style=\"font-size: 15px;\">\u6570\u636e\u5904\u7406\u5b8c\u6210\uff0c\u7ecf\u8fc7\u5c01\u88c5\u540e\u7684\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u653e\u5728\u81ea\u5df1\u81ea\u5b9a\u4e49\u7684\u6a21\u5757\u540d\u6587\u4ef6\u4e0b\u9762\uff0c\u4ee5\u540e\u53ef\u4ee5\u65b9\u4fbf\u76f4\u63a5\u5bfc\u5165\u51fd\u6570\u540d\u5373\u53ef\uff0c\u53ef\u4ee5\u53c2\u8003<\/span><span style=\"font-size: 15px;\">\u5c06\u81ea\u5b9a\u4e49\u5e38\u7528\u7684\u4e00\u4e9b\u51fd\u6570\u5c01\u88c5\u6210\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u7684\u6a21\u5757\u65b9\u6cd5\u3002<\/span><\/p>\n<h1 style=\"margin-bottom: 16px; font-size: 18px; white-space: normal; box-sizing: border-box; outline: 0px; color: #4d4d4d; line-height: 26px; overflow-wrap: break-word; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-variant-ligatures: common-ligatures; text-align: center; background-color: #ffffff;\"><span style=\"color: #ff6827;\"><strong><span style=\"font-size: 15px;\">4. \u5168\u90e8\u51fd\u6570\u4ee3\u7801<\/span><\/strong><\/span><\/h1>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">#\u6a21\u7cca\u5339\u914d<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__function\"><span class=\"code-snippet__keyword\">def<\/span> <span class=\"code-snippet__title\">fuzzy_merge<\/span><span class=\"code-snippet__params\">(df_1, df_2, key1, key2, threshold=<span class=\"code-snippet__number\">90<\/span>, limit=<span class=\"code-snippet__number\">2<\/span>)<\/span>:<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__string\">\"\"\"<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    :param df_1: the left table to join<\/span><\/code><code><span class=\"code-snippet_outer\">    :param df_2: the right table to join<\/span><\/code><code><span class=\"code-snippet_outer\">    :param key1: key column of the left table<\/span><\/code><code><span class=\"code-snippet_outer\">    :param key2: key column of the right table<\/span><\/code><code><span class=\"code-snippet_outer\">    :param threshold: how close the matches should be to return a match, based on Levenshtein distance<\/span><\/code><code><span class=\"code-snippet_outer\">    :param limit: the amount of matches that will get returned, these are sorted high to low<\/span><\/code><code><span class=\"code-snippet_outer\">    :return: dataframe with boths keys and matches<\/span><\/code><code><span class=\"code-snippet_outer\">    \"\"\"<\/span><\/code><code><span class=\"code-snippet_outer\">    s = df_2[key2].tolist()<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">    m = df_1[key1].apply(<span class=\"code-snippet__keyword\">lambda<\/span> x: process.extract(x, s, limit=limit))    <\/span><\/code><code><span class=\"code-snippet_outer\">    df_1[<span class=\"code-snippet__string\">'matches'<\/span>] = m<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">    m2 = df_1[<span class=\"code-snippet__string\">'matches'<\/span>].apply(<span class=\"code-snippet__keyword\">lambda<\/span> x: [i[<span class=\"code-snippet__number\">0<\/span>] <span class=\"code-snippet__keyword\">for<\/span> i <span class=\"code-snippet__keyword\">in<\/span> x <span class=\"code-snippet__keyword\">if<\/span> i[<span class=\"code-snippet__number\">1<\/span>] &gt;= threshold][<span class=\"code-snippet__number\">0<\/span>] <span class=\"code-snippet__keyword\">if<\/span> len([i[<span class=\"code-snippet__number\">0<\/span>] <span class=\"code-snippet__keyword\">for<\/span> i <span class=\"code-snippet__keyword\">in<\/span> x <span class=\"code-snippet__keyword\">if<\/span> i[<span class=\"code-snippet__number\">1<\/span>] &gt;= threshold]) &gt; <span class=\"code-snippet__number\">0<\/span> <span class=\"code-snippet__keyword\">else<\/span> <span class=\"code-snippet__string\">''<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\">    df_1[<span class=\"code-snippet__string\">'matches'<\/span>] = m2<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__keyword\">return<\/span> df_1<\/span><\/code><code>    <\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__keyword\">from<\/span> fuzzywuzzy <span class=\"code-snippet__keyword\">import<\/span> fuzz<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__keyword\">from<\/span> fuzzywuzzy <span class=\"code-snippet__keyword\">import<\/span> process<\/span><\/code><code><span class=\"code-snippet_outer\">\n<\/span><\/code><code><span class=\"code-snippet_outer\">df = fuzzy_merge(data, company, <span class=\"code-snippet__string\">'\u516c\u53f8\u540d\u79f0'<\/span>, <span class=\"code-snippet__string\">'\u516c\u53f8\u540d\u79f0'<\/span>, threshold=<span class=\"code-snippet__number\">90<\/span>)<\/span><\/code><code><span class=\"code-snippet_outer\">df<\/span><\/code><\/pre>\n<\/section>\n<p style=\"white-space: normal;\">\u8f6c\u81ea\uff1ahttps:\/\/mp.weixin.qq.com\/s\/NU7cHq0nMDzcRHkjI2eEZg<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1aBe_melting blog.csdn.net\/lys_828\/article\/details\/106 &hellip; <a href=\"http:\/\/www.zhushiyao.com\/?p=45603\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cGitHub \u6807\u661f 7.4k\uff01Python \u9b54\u6cd5\u5e93\u4e4b FuzzyWuzzy\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[8],"_links":{"self":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/45603"}],"collection":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45603"}],"version-history":[{"count":2,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/45603\/revisions"}],"predecessor-version":[{"id":45612,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/45603\/revisions\/45612"}],"wp:attachment":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45603"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}