{"id":1163854,"date":"2025-01-15T14:59:53","date_gmt":"2025-01-15T06:59:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1163854.html"},"modified":"2025-01-15T14:59:57","modified_gmt":"2025-01-15T06:59:57","slug":"python%e5%a6%82%e4%bd%95%e5%88%b6%e4%bd%9c%e4%b8%ad%e6%96%87%e5%81%9c%e8%af%8d%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1163854.html","title":{"rendered":"python\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25204529\/cb998179-9292-4bcd-a761-cb2c46083828.webp\" alt=\"python\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\" \/><\/p>\n<p><p> \u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u662f\u5904\u7406\u4e2d\u6587\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u4e2d\u7684\u91cd\u8981\u4e00\u6b65\u3002<strong>\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u786e\u5b9a\u505c\u8bcd\u8868\u6765\u6e90\u3001\u6e05\u7406\u548c\u7b5b\u9009\u505c\u8bcd\u3001\u4fdd\u5b58\u505c\u8bcd\u8868<\/strong>\u3002\u5176\u4e2d\uff0c\u201c\u786e\u5b9a\u505c\u8bcd\u8868\u6765\u6e90\u201d\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65\u3002\u53ef\u4ee5\u4ece\u5df2\u6709\u7684\u505c\u8bcd\u8868\u8d44\u6e90\u3001\u7ed3\u5408\u5177\u4f53\u9879\u76ee\u9700\u6c42\u548c\u9886\u57df\u7279\u70b9\u6765\u786e\u5b9a\u505c\u8bcd\u8868\u7684\u8bcd\u6c47\u8303\u56f4\uff0c\u5e76\u8fdb\u884c\u9002\u5f53\u7684\u6e05\u7406\u548c\u7b5b\u9009\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u9ad8\u8d28\u91cf\u7684\u505c\u8bcd\u8868\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u786e\u5b9a\u505c\u8bcd\u8868\u6765\u6e90<\/strong><\/h2>\n<p><p>\u5728\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u65f6\uff0c\u9996\u5148\u9700\u8981\u786e\u5b9a\u505c\u8bcd\u8868\u7684\u6765\u6e90\u3002\u5e38\u89c1\u7684\u6765\u6e90\u6709\u516c\u5f00\u7684\u505c\u8bcd\u8868\u3001\u9886\u57df\u4e13\u7528\u7684\u505c\u8bcd\u8868\u4ee5\u53ca\u6839\u636e\u9879\u76ee\u9700\u6c42\u81ea\u5b9a\u4e49\u7684\u505c\u8bcd\u8868\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u516c\u5f00\u7684\u505c\u8bcd\u8868<\/h2>\n<\/p>\n<p><p>\u516c\u5f00\u7684\u505c\u8bcd\u8868\u662f\u6307\u5df2\u7ecf\u6709\u5f88\u591a\u7814\u7a76\u4eba\u5458\u548c\u673a\u6784\u6574\u7406\u597d\u7684\u4e2d\u6587\u505c\u8bcd\u8868\u3002\u6bd4\u5982\uff1a\u767e\u5ea6\u505c\u8bcd\u8868\u3001\u54c8\u5de5\u5927\u505c\u8bcd\u8868\u3001\u65af\u5766\u798f\u4e2d\u6587\u505c\u8bcd\u8868\u7b49\u3002\u8fd9\u4e9b\u505c\u8bcd\u8868\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8d44\u6e90\u83b7\u53d6\uff0c\u5e76\u4e14\u5df2\u7ecf\u8fc7\u5927\u91cf\u5b9e\u8df5\u9a8c\u8bc1\uff0c\u5177\u6709\u8f83\u9ad8\u7684\u901a\u7528\u6027\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u9886\u57df\u4e13\u7528\u505c\u8bcd\u8868<\/h2>\n<\/p>\n<p><p>\u5728\u7279\u5b9a\u7684\u9886\u57df\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u9488\u5bf9\u6027\u5730\u5236\u4f5c\u505c\u8bcd\u8868\u3002\u4f8b\u5982\uff0c\u5728\u533b\u7597\u9886\u57df\u3001\u6cd5\u5f8b\u9886\u57df\u7b49\uff0c\u4e0d\u540c\u9886\u57df\u7684\u6587\u672c\u6709\u5176\u7279\u6709\u7684\u505c\u8bcd\u9700\u6c42\u3002\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u9886\u57df\u5185\u5927\u91cf\u6587\u672c\uff0c\u63d0\u53d6\u51fa\u9ad8\u9891\u4e14\u65e0\u610f\u4e49\u7684\u8bcd\u8bed\uff0c\u5236\u4f5c\u9886\u57df\u4e13\u7528\u7684\u505c\u8bcd\u8868\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u81ea\u5b9a\u4e49\u505c\u8bcd\u8868<\/h2>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u516c\u5f00\u7684\u505c\u8bcd\u8868\u548c\u9886\u57df\u4e13\u7528\u7684\u505c\u8bcd\u8868\u53ef\u80fd\u65e0\u6cd5\u5b8c\u5168\u6ee1\u8db3\u9879\u76ee\u7684\u9700\u6c42\u3002\u8fd9\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u7684\u7279\u70b9\u548c\u5b9e\u9645\u9700\u6c42\uff0c\u81ea\u5b9a\u4e49\u505c\u8bcd\u8868\u3002\u901a\u8fc7\u5bf9\u9879\u76ee\u4e2d\u7684\u6587\u672c\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\uff0c\u7b5b\u9009\u51fa\u5e38\u89c1\u4e14\u5bf9\u6587\u672c\u5206\u6790\u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u7684\u8bcd\u8bed\uff0c\u52a0\u5165\u5230\u505c\u8bcd\u8868\u4e2d\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u6e05\u7406\u548c\u7b5b\u9009\u505c\u8bcd<\/strong><\/h2>\n<p><p>\u786e\u5b9a\u4e86\u505c\u8bcd\u8868\u7684\u6765\u6e90\u540e\uff0c\u9700\u8981\u5bf9\u505c\u8bcd\u8868\u8fdb\u884c\u6e05\u7406\u548c\u7b5b\u9009\uff0c\u4ee5\u786e\u4fdd\u505c\u8bcd\u8868\u7684\u8d28\u91cf\u548c\u9002\u7528\u6027\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u53bb\u9664\u91cd\u590d\u8bcd<\/h2>\n<\/p>\n<p><p>\u5728\u591a\u79cd\u6765\u6e90\u7684\u505c\u8bcd\u8868\u4e2d\uff0c\u53ef\u80fd\u4f1a\u5b58\u5728\u91cd\u590d\u7684\u8bcd\u8bed\u3002\u9700\u8981\u5bf9\u505c\u8bcd\u8868\u8fdb\u884c\u53bb\u91cd\u5904\u7406\uff0c\u786e\u4fdd\u6bcf\u4e2a\u8bcd\u8bed\u5728\u505c\u8bcd\u8868\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u53bb\u9664\u65e0\u5173\u8bcd<\/h2>\n<\/p>\n<p><p>\u6709\u4e9b\u505c\u8bcd\u8868\u4e2d\u53ef\u80fd\u4f1a\u5305\u542b\u4e00\u4e9b\u65e0\u5173\u7684\u8bcd\u8bed\u6216\u5b57\u7b26\uff0c\u9700\u8981\u6839\u636e\u9879\u76ee\u7684\u5b9e\u9645\u9700\u6c42\u8fdb\u884c\u7b5b\u9009\uff0c\u53bb\u9664\u8fd9\u4e9b\u65e0\u5173\u7684\u8bcd\u8bed\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u589e\u52a0\u7279\u5b9a\u8bcd<\/h2>\n<\/p>\n<p><p>\u5728\u6e05\u7406\u548c\u7b5b\u9009\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u6839\u636e\u9879\u76ee\u7684\u7279\u70b9\uff0c\u589e\u52a0\u4e00\u4e9b\u7279\u5b9a\u7684\u505c\u8bcd\u3002\u4f8b\u5982\uff0c\u5728\u793e\u4ea4\u5a92\u4f53\u6587\u672c\u5904\u7406\u4e2d\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e9b\u5e38\u89c1\u7684\u8868\u60c5\u7b26\u53f7\u3001\u7f51\u7edc\u7528\u8bed\u7b49\u52a0\u5165\u5230\u505c\u8bcd\u8868\u4e2d\u3002<\/p>\n<\/p>\n<h2><strong>\u4e09\u3001\u4fdd\u5b58\u505c\u8bcd\u8868<\/strong><\/h2>\n<p><p>\u7ecf\u8fc7\u6e05\u7406\u548c\u7b5b\u9009\u540e\uff0c\u5f97\u5230\u4e00\u4e2a\u9ad8\u8d28\u91cf\u7684\u505c\u8bcd\u8868\u3002\u53ef\u4ee5\u5c06\u505c\u8bcd\u8868\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\u6216\u5176\u4ed6\u683c\u5f0f\uff0c\u65b9\u4fbf\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6<\/h2>\n<\/p>\n<p><p>\u5c06\u505c\u8bcd\u8868\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\uff08\u4f8b\u5982stopwords.txt\uff09\uff0c\u6bcf\u884c\u4e00\u4e2a\u505c\u8bcd\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5c06\u505c\u8bcd\u8868\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">stopwords = [&quot;\u7684&quot;, &quot;\u4e86&quot;, &quot;\u5728&quot;, &quot;\u662f&quot;, &quot;\u6211&quot;, &quot;\u6709&quot;, &quot;\u548c&quot;, &quot;\u5c31&quot;, &quot;\u4e0d&quot;, &quot;\u4eba&quot;, &quot;\u90fd&quot;, &quot;\u4e00&quot;, &quot;\u4e00\u4e2a&quot;, &quot;\u4e0a&quot;, &quot;\u4e5f&quot;, &quot;\u5f88&quot;, &quot;\u5230&quot;, &quot;\u8bf4&quot;, &quot;\u8981&quot;, &quot;\u53bb&quot;, &quot;\u4f60&quot;, &quot;\u4f1a&quot;, &quot;\u7740&quot;, &quot;\u6ca1\u6709&quot;, &quot;\u770b&quot;, &quot;\u597d&quot;, &quot;\u81ea\u5df1&quot;, &quot;\u8fd9&quot;]<\/p>\n<p>with open(&quot;stopwords.txt&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    for word in stopwords:<\/p>\n<p>        f.write(word + &quot;\\n&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u4fdd\u5b58\u4e3a\u5176\u4ed6\u683c\u5f0f<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u6587\u672c\u6587\u4ef6\u5916\uff0c\u8fd8\u53ef\u4ee5\u5c06\u505c\u8bcd\u8868\u4fdd\u5b58\u4e3aJSON\u3001CSV\u7b49\u5176\u4ed6\u683c\u5f0f\u3002\u5177\u4f53\u4fdd\u5b58\u65b9\u5f0f\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u9009\u62e9\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u505c\u8bcd\u8868\u5728\u9879\u76ee\u4e2d\u7684\u5e94\u7528<\/strong><\/h2>\n<p><p>\u5236\u4f5c\u597d\u505c\u8bcd\u8868\u540e\uff0c\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u5e94\u7528\u505c\u8bcd\u8868\u8fdb\u884c\u6587\u672c\u9884\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u53bb\u9664\u505c\u8bcd<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6587\u672c\u9884\u5904\u7406\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u505c\u8bcd\u8868\u53bb\u9664\u6587\u672c\u4e2d\u7684\u505c\u8bcd\u3002\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684<code>jieba<\/code>\u5e93\u8fdb\u884c\u5206\u8bcd\uff0c\u7136\u540e\u53bb\u9664\u505c\u8bcd\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<h2><strong>\u8bfb\u53d6\u505c\u8bcd\u8868<\/strong><\/h2>\n<p>with open(&quot;stopwords.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    stopwords = set(f.read().splitlines())<\/p>\n<h2><strong>\u793a\u4f8b\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;\u6211\u5728\u5b66\u4e60\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868&quot;<\/p>\n<h2><strong>\u5206\u8bcd<\/strong><\/h2>\n<p>words = jieba.lcut(text)<\/p>\n<h2><strong>\u53bb\u9664\u505c\u8bcd<\/strong><\/h2>\n<p>filtered_words = [word for word in words if word not in stopwords]<\/p>\n<p>print(filtered_words)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u8bcd\u9891\u7edf\u8ba1<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6587\u672c\u5206\u6790\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u505c\u8bcd\u8868\u53bb\u9664\u505c\u8bcd\uff0c\u7136\u540e\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<h2><strong>\u793a\u4f8b\u6587\u672c<\/strong><\/h2>\n<p>texts = [&quot;\u6211\u5728\u5b66\u4e60\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868&quot;, &quot;\u505c\u8bcd\u8868\u5728\u6587\u672c\u5904\u7406\u4e2d\u975e\u5e38\u91cd\u8981&quot;]<\/p>\n<h2><strong>\u5206\u8bcd\u5e76\u53bb\u9664\u505c\u8bcd<\/strong><\/h2>\n<p>words = []<\/p>\n<p>for text in texts:<\/p>\n<p>    words.extend([word for word in jieba.lcut(text) if word not in stopwords])<\/p>\n<h2><strong>\u8bcd\u9891\u7edf\u8ba1<\/strong><\/h2>\n<p>word_counts = Counter(words)<\/p>\n<p>print(word_counts)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3\u3001\u6587\u672c\u5411\u91cf\u5316<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6587\u672c\u5411\u91cf\u5316\uff08\u5982TF-IDF\u3001\u8bcd\u888b\u6a21\u578b\u7b49\uff09\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u505c\u8bcd\u8868\u53bb\u9664\u505c\u8bcd\uff0c\u4ee5\u63d0\u9ad8\u5411\u91cf\u5316\u7684\u6548\u679c\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.feature_extraction.text import TfidfVectorizer<\/p>\n<h2><strong>\u793a\u4f8b\u6587\u672c<\/strong><\/h2>\n<p>texts = [&quot;\u6211\u5728\u5b66\u4e60\u5982\u4f55\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868&quot;, &quot;\u505c\u8bcd\u8868\u5728\u6587\u672c\u5904\u7406\u4e2d\u975e\u5e38\u91cd\u8981&quot;]<\/p>\n<h2><strong>\u5206\u8bcd\u5e76\u53bb\u9664\u505c\u8bcd<\/strong><\/h2>\n<p>filtered_texts = []<\/p>\n<p>for text in texts:<\/p>\n<p>    filtered_words = [word for word in jieba.lcut(text) if word not in stopwords]<\/p>\n<p>    filtered_texts.append(&quot; &quot;.join(filtered_words))<\/p>\n<h2><strong>\u6587\u672c\u5411\u91cf\u5316<\/strong><\/h2>\n<p>vectorizer = TfidfVectorizer()<\/p>\n<p>tfidf_matrix = vectorizer.fit_transform(filtered_texts)<\/p>\n<p>print(tfidf_matrix.toarray())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u662f\u4e2d\u6587\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u901a\u8fc7\u786e\u5b9a\u505c\u8bcd\u8868\u6765\u6e90\u3001\u6e05\u7406\u548c\u7b5b\u9009\u505c\u8bcd\u3001\u4fdd\u5b58\u505c\u8bcd\u8868\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u9ad8\u8d28\u91cf\u7684\u505c\u8bcd\u8868\uff0c\u5e76\u5728\u9879\u76ee\u4e2d\u5e94\u7528\u505c\u8bcd\u8868\u8fdb\u884c\u6587\u672c\u9884\u5904\u7406\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u5236\u4f5c\u548c\u4f7f\u7528\u4e2d\u6587\u505c\u8bcd\u8868\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u9002\u5408\u7684\u4e2d\u6587\u505c\u8bcd\u5e93\uff1f<\/strong><br \/>\u5728\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u505c\u8bcd\u5e93\u975e\u5e38\u91cd\u8981\u3002\u53ef\u4ee5\u4ece\u516c\u5f00\u7684\u4e2d\u6587\u505c\u8bcd\u5e93\u4e2d\u83b7\u53d6\uff0c\u5982\u767e\u5ea6\u505c\u8bcd\u8868\u6216\u54c8\u5de5\u5927\u7684\u4e2d\u6587\u505c\u8bcd\u5e93\u3002\u8fd9\u4e9b\u8d44\u6e90\u901a\u5e38\u7ecf\u8fc7\u4e13\u4e1a\u4eba\u58eb\u7684\u6574\u7406\uff0c\u6db5\u76d6\u4e86\u5927\u91cf\u5e38\u89c1\u7684\u65e0\u610f\u4e49\u8bcd\u6c47\u3002\u6839\u636e\u5177\u4f53\u7684\u6587\u672c\u5206\u6790\u9700\u6c42\uff0c\u60a8\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u505c\u8bcd\u8868\uff0c\u6dfb\u52a0\u7279\u5b9a\u9886\u57df\u7684\u505c\u7528\u8bcd\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u52a0\u8f7d\u548c\u4f7f\u7528\u505c\u8bcd\u8868\uff1f<\/strong><br \/>\u52a0\u8f7d\u505c\u8bcd\u8868\u65f6\uff0c\u60a8\u53ef\u4ee5\u5c06\u505c\u8bcd\u8868\u4ee5\u6587\u672c\u6587\u4ef6\u7684\u5f62\u5f0f\u5b58\u50a8\uff0c\u6bcf\u884c\u4e00\u4e2a\u505c\u7528\u8bcd\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>open()<\/code>\u51fd\u6570\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u96c6\u5408\u6216\u5217\u8868\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">with open(&#39;stopwords.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:\n    stopwords = set(f.read().splitlines())\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u5728\u6587\u672c\u5904\u7406\u65f6\u8f7b\u677e\u5730\u68c0\u67e5\u6bcf\u4e2a\u8bcd\u662f\u5426\u5728\u505c\u8bcd\u8868\u4e2d\u3002<\/p>\n<p><strong>\u505c\u8bcd\u8868\u7684\u66f4\u65b0\u9891\u7387\u5e94\u8be5\u662f\u600e\u6837\u7684\uff1f<\/strong><br \/>\u505c\u8bcd\u8868\u7684\u66f4\u65b0\u9891\u7387\u901a\u5e38\u53d6\u51b3\u4e8e\u9879\u76ee\u7684\u9700\u6c42\u548c\u6587\u672c\u7684\u53d8\u5316\u3002\u5982\u679c\u5904\u7406\u7684\u6587\u672c\u6765\u6e90\u4e8e\u7279\u5b9a\u9886\u57df\u6216\u884c\u4e1a\uff0c\u5efa\u8bae\u5b9a\u671f\u8bc4\u4f30\u548c\u66f4\u65b0\u505c\u8bcd\u8868\uff0c\u4ee5\u786e\u4fdd\u5176\u51c6\u786e\u6027\u548c\u9002\u7528\u6027\u3002\u4f8b\u5982\uff0c\u968f\u7740\u65b0\u8bcd\u6c47\u7684\u51fa\u73b0\u6216\u8bed\u8a00\u4f7f\u7528\u4e60\u60ef\u7684\u53d8\u5316\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u505c\u8bcd\u8868\u8fdb\u884c\u8c03\u6574\uff0c\u4ee5\u63d0\u9ad8\u6587\u672c\u5206\u6790\u7684\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u662f\u5904\u7406\u4e2d\u6587\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u4e2d\u7684\u91cd\u8981\u4e00\u6b65\u3002\u5236\u4f5c\u4e2d\u6587\u505c\u8bcd\u8868\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u786e\u5b9a\u505c\u8bcd\u8868\u6765\u6e90\u3001\u6e05\u7406\u548c\u7b5b\u9009\u505c\u8bcd [&hellip;]","protected":false},"author":3,"featured_media":1163863,"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\/1163854"}],"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=1163854"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1163854\/revisions"}],"predecessor-version":[{"id":1163865,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1163854\/revisions\/1163865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1163863"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1163854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1163854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1163854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}