{"id":1183815,"date":"2025-01-15T19:19:00","date_gmt":"2025-01-15T11:19:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1183815.html"},"modified":"2025-01-15T19:19:03","modified_gmt":"2025-01-15T11:19:03","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%86%99%e6%96%87%e7%8c%ae%e7%bb%bc%e8%bf%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1183815.html","title":{"rendered":"\u5982\u4f55\u7528python\u5199\u6587\u732e\u7efc\u8ff0"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25133446\/5a198be9-ebac-4c61-8e2e-f8bcbedac18e.webp\" alt=\"\u5982\u4f55\u7528python\u5199\u6587\u732e\u7efc\u8ff0\" \/><\/p>\n<p><p> <strong>\u7528Python\u5199\u6587\u732e\u7efc\u8ff0\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u52a8\u5316\u548c\u534a\u81ea\u52a8\u5316\u7684\u65b9\u5f0f\uff0c\u5229\u7528Python\u7684\u4e30\u5bcc\u5e93\u548c\u5de5\u5177\uff0c\u63d0\u9ad8\u6587\u732e\u6536\u96c6\u3001\u5904\u7406\u548c\u5206\u6790\u7684\u6548\u7387\u3002\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u6587\u732e\u68c0\u7d22\u4e0e\u6536\u96c6\u3001\u6587\u732e\u6570\u636e\u5904\u7406\u3001\u6587\u732e\u5206\u6790\u4e0e\u53ef\u89c6\u5316\u3001\u6587\u732e\u7efc\u8ff0\u64b0\u5199\u3002<\/strong>\u5176\u4e2d\uff0c\u6587\u732e\u6570\u636e\u5904\u7406\u662f\u5173\u952e\u73af\u8282\uff0c\u901a\u8fc7Python\u8fdb\u884c\u6279\u91cf\u5904\u7406\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u6548\u7387\uff0c\u5e76\u4e14\u53ef\u4ee5\u5229\u7528\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u6280\u672f\u8fdb\u884c\u5185\u5bb9\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6587\u732e\u68c0\u7d22\u4e0e\u6536\u96c6<\/h3>\n<\/p>\n<p><p>\u6587\u732e\u7efc\u8ff0\u7684\u7b2c\u4e00\u6b65\u662f\u68c0\u7d22\u548c\u6536\u96c6\u76f8\u5173\u6587\u732e\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ece\u5404\u5927\u6570\u636e\u5e93\uff08\u5982PubMed\u3001IEEE\u3001Google Scholar\u7b49\uff09\u4e2d\u83b7\u53d6\u6587\u732e\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528API\u8fdb\u884c\u6587\u732e\u68c0\u7d22<\/h4>\n<\/p>\n<p><p>\u8bb8\u591a\u6587\u732e\u6570\u636e\u5e93\u63d0\u4f9bAPI\u63a5\u53e3\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u811a\u672c\u76f4\u63a5\u8bbf\u95ee\u5e76\u4e0b\u8f7d\u6587\u732e\u6570\u636e\u3002\u4f8b\u5982\uff0cPubMed\u63d0\u4f9b\u4e86Entrez Programming Utilities (E-utilities) API\uff0c\u4f7f\u7528Biopython\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u68c0\u7d22\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from Bio import Entrez<\/p>\n<h2><strong>\u8bbe\u7f6e\u90ae\u7bb1<\/strong><\/h2>\n<p>Entrez.em<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l = &quot;your.email@example.com&quot;<\/p>\n<h2><strong>\u68c0\u7d22PubMed\u6570\u636e\u5e93<\/strong><\/h2>\n<p>handle = Entrez.esearch(db=&quot;pubmed&quot;, term=&quot;machine learning&quot;, retmax=100)<\/p>\n<p>record = Entrez.read(handle)<\/p>\n<p>handle.close()<\/p>\n<h2><strong>\u83b7\u53d6\u6587\u732eID\u5217\u8868<\/strong><\/h2>\n<p>id_list = record[&quot;IdList&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u722c\u866b\u6280\u672f\u8fdb\u884c\u6587\u732e\u6536\u96c6<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6ca1\u6709API\u63a5\u53e3\u7684\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u722c\u866b\u6280\u672f\u3002Python\u7684BeautifulSoup\u548cScrapy\u5e93\u53ef\u4ee5\u7528\u4e8e\u7f51\u9875\u89e3\u6790\u548c\u6570\u636e\u63d0\u53d6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>url = &quot;https:\/\/scholar.google.com\/scholar?q=machine+learning&quot;<\/p>\n<p>response = requests.get(url)<\/p>\n<p>soup = BeautifulSoup(response.content, &quot;html.parser&quot;)<\/p>\n<h2><strong>\u63d0\u53d6\u6587\u732e\u4fe1\u606f<\/strong><\/h2>\n<p>for item in soup.find_all(&quot;div&quot;, class_=&quot;gs_ri&quot;):<\/p>\n<p>    title = item.find(&quot;h3&quot;).text<\/p>\n<p>    summary = item.find(&quot;div&quot;, class_=&quot;gs_rs&quot;).text<\/p>\n<p>    print(title)<\/p>\n<p>    print(summary)<\/p>\n<p>    print(&quot;\\n&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u6587\u732e\u6570\u636e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u6587\u732e\u6570\u636e\u5904\u7406\u5305\u62ec\u5bf9\u6536\u96c6\u5230\u7684\u6587\u732e\u4fe1\u606f\u8fdb\u884c\u6574\u7406\u3001\u6e05\u6d17\u548c\u683c\u5f0f\u5316\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u3002Python\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u5982Pandas\u548cNumpy\uff0c\u53ef\u4ee5\u9ad8\u6548\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6570\u636e\u6e05\u6d17\u4e0e\u6574\u7406<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pandas\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u4e0e\u6574\u7406\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u6587\u732e\u4fe1\u606f\u5b58\u50a8\u5728DataFrame\u4e2d\uff0c\u5e76\u8fdb\u884c\u5fc5\u8981\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u6587\u732eDataFrame<\/strong><\/h2>\n<p>data = {&#39;Title&#39;: titles, &#39;Summary&#39;: summaries}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u6570\u636e\u6e05\u6d17\uff1a\u53bb\u9664\u91cd\u590d\u9879\u3001\u7f3a\u5931\u503c\u7b49<\/strong><\/h2>\n<p>df.drop_duplicates(inplace=True)<\/p>\n<p>df.dropna(inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u683c\u5f0f\u5316\u4e0e\u5b58\u50a8<\/h4>\n<\/p>\n<p><p>\u5c06\u5904\u7406\u540e\u7684\u6587\u732e\u4fe1\u606f\u683c\u5f0f\u5316\uff0c\u5e76\u5b58\u50a8\u4e3aCSV\u6216Excel\u6587\u4ef6\uff0c\u4fbf\u4e8e\u540e\u7eed\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b58\u50a8\u4e3aCSV\u6587\u4ef6<\/p>\n<p>df.to_csv(&quot;literature_review.csv&quot;, index=False)<\/p>\n<h2><strong>\u5b58\u50a8\u4e3aExcel\u6587\u4ef6<\/strong><\/h2>\n<p>df.to_excel(&quot;literature_review.xlsx&quot;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6587\u732e\u5206\u6790\u4e0e\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><p>\u6587\u732e\u5206\u6790\u4e0e\u53ef\u89c6\u5316\u662f\u6587\u732e\u7efc\u8ff0\u7684\u91cd\u8981\u73af\u8282\uff0c\u901a\u8fc7\u5206\u6790\u6587\u732e\u5185\u5bb9\uff0c\u63d0\u53d6\u5173\u952e\u4fe1\u606f\uff0c\u5e76\u8fdb\u884c\u56fe\u8868\u5c55\u793a\uff0c\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u7814\u7a76\u73b0\u72b6\u548c\u8d8b\u52bf\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6587\u732e\u5185\u5bb9\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u6280\u672f\uff0c\u53ef\u4ee5\u5bf9\u6587\u732e\u5185\u5bb9\u8fdb\u884c\u6df1\u5165\u5206\u6790\u3002Python\u7684NLTK\u548cspaCy\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684NLP\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import nltk<\/p>\n<p>from nltk.corpus import stopwords<\/p>\n<p>from nltk.tokenize import word_tokenize<\/p>\n<h2><strong>\u6587\u672c\u9884\u5904\u7406<\/strong><\/h2>\n<p>stop_words = set(stopwords.words(&#39;english&#39;))<\/p>\n<p>df[&#39;Processed_Summary&#39;] = df[&#39;Summary&#39;].apply(lambda x: &#39; &#39;.join([word for word in word_tokenize(x.lower()) if word.isalnum() and word not in stop_words]))<\/p>\n<h2><strong>\u8bcd\u9891\u7edf\u8ba1<\/strong><\/h2>\n<p>from collections import Counter<\/p>\n<p>all_words = &#39; &#39;.join(df[&#39;Processed_Summary&#39;]).split()<\/p>\n<p>word_freq = Counter(all_words)<\/p>\n<p>print(word_freq.most_common(10))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6587\u732e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684Matplotlib\u548cSeaborn\u5e93\uff0c\u53ef\u4ee5\u5c06\u5206\u6790\u7ed3\u679c\u8fdb\u884c\u53ef\u89c6\u5316\u5c55\u793a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<h2><strong>\u8bcd\u9891\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>word_freq_df = pd.DataFrame(word_freq.most_common(10), columns=[&#39;Word&#39;, &#39;Frequency&#39;])<\/p>\n<p>sns.barplot(x=&#39;Word&#39;, y=&#39;Frequency&#39;, data=word_freq_df)<\/p>\n<p>plt.xticks(rotation=45)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6587\u732e\u7efc\u8ff0\u64b0\u5199<\/h3>\n<\/p>\n<p><p>\u64b0\u5199\u6587\u732e\u7efc\u8ff0\u65f6\uff0c\u53ef\u4ee5\u5229\u7528Python\u8fdb\u884c\u8f85\u52a9\uff0c\u751f\u6210\u7ed3\u6784\u5316\u7684\u5185\u5bb9\u6846\u67b6\uff0c\u5e76\u81ea\u52a8\u586b\u5145\u90e8\u5206\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u751f\u6210\u5185\u5bb9\u6846\u67b6<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u751f\u6210\u6587\u732e\u7efc\u8ff0\u7684\u5185\u5bb9\u6846\u67b6\uff0c\u5305\u62ec\u5f15\u8a00\u3001\u7814\u7a76\u73b0\u72b6\u3001\u8ba8\u8bba\u4e0e\u5206\u6790\u3001\u7ed3\u8bba\u7b49\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sections = [&quot;Introduction&quot;, &quot;Literature Review&quot;, &quot;Discussion&quot;, &quot;Conclusion&quot;]<\/p>\n<p>for section in sections:<\/p>\n<p>    print(f&quot;## {section}\\n&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u81ea\u52a8\u586b\u5145\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>\u6839\u636e\u6587\u732e\u5206\u6790\u7ed3\u679c\uff0c\u81ea\u52a8\u586b\u5145\u90e8\u5206\u4fe1\u606f\uff0c\u5982\u7814\u7a76\u73b0\u72b6\u4e2d\u7684\u5173\u952e\u8bcd\u7edf\u8ba1\u3001\u7814\u7a76\u8d8b\u52bf\u56fe\u8868\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u586b\u5145\u5173\u952e\u8bcd\u7edf\u8ba1<\/p>\n<p>print(&quot;### Keywords Statistics\\n&quot;)<\/p>\n<p>print(word_freq_df.to_string(index=False))<\/p>\n<h2><strong>\u63d2\u5165\u7814\u7a76\u8d8b\u52bf\u56fe\u8868<\/strong><\/h2>\n<p>print(&quot;### Research Trends\\n&quot;)<\/p>\n<p>plt.savefig(&quot;research_trends.png&quot;)<\/p>\n<p>print(&quot;![Research Trends](research_trends.png)&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5229\u7528Python\u9ad8\u6548\u5730\u5b8c\u6210\u6587\u732e\u7efc\u8ff0\u7684\u64b0\u5199\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u548c\u6587\u732e\u5206\u6790\u7684\u6df1\u5ea6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u81ea\u52a8\u5316\u6587\u732e\u7efc\u8ff0\u7684\u8fc7\u7a0b\uff1f<\/strong><br \/>\u4f7f\u7528Python\u8fdb\u884c\u6587\u732e\u7efc\u8ff0\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u5e93\u548c\u5de5\u5177\u6765\u7b80\u5316\u6d41\u7a0b\u3002\u4f8b\u5982\uff0c\u4f7f\u7528BeautifulSoup\u548cRequests\u5e93\u53ef\u4ee5\u6293\u53d6\u5b66\u672f\u7f51\u7ad9\u7684\u6570\u636e\uff0c\u800cPandas\u5219\u53ef\u4ee5\u7528\u6765\u7ba1\u7406\u548c\u5206\u6790\u6587\u732e\u6570\u636e\u3002\u6b64\u5916\uff0c\u5229\u7528\u6587\u732e\u7ba1\u7406\u5de5\u5177\u5982Zotero\u6216Mendeley\u7684API\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6587\u732e\u7684\u5bfc\u5165\u4e0e\u5bfc\u51fa\uff0c\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<p><strong>\u5728\u64b0\u5199\u6587\u732e\u7efc\u8ff0\u65f6\uff0cPython\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u5e93\u548c\u5de5\u5177\uff1f<\/strong><br \/>Python\u6709\u8bb8\u591a\u5f3a\u5927\u7684\u5e93\u53ef\u4ee5\u5e2e\u52a9\u64b0\u5199\u6587\u732e\u7efc\u8ff0\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ecNumPy\u548cPandas\u7528\u4e8e\u6570\u636e\u5904\u7406\uff0cMatplotlib\u548cSeaborn\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\uff0cScikit-learn\u7528\u4e8e\u6570\u636e\u5206\u6790\u3002\u6b64\u5916\uff0c\u4f7f\u7528Natural Language Toolkit\uff08NLTK\uff09\u548cSpaCy\u53ef\u4ee5\u5e2e\u52a9\u8fdb\u884c\u6587\u672c\u5206\u6790\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff0c\u4ee5\u63d0\u53d6\u6587\u732e\u4e2d\u7684\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u4f7f\u7528Python\u64b0\u5199\u7684\u6587\u732e\u7efc\u8ff0\u5177\u6709\u9ad8\u8d28\u91cf\u548c\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u786e\u4fdd\u6587\u732e\u7efc\u8ff0\u8d28\u91cf\u7684\u5173\u952e\u5728\u4e8e\u6587\u732e\u7684\u9009\u62e9\u548c\u6570\u636e\u7684\u5904\u7406\u3002\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u9ad8\u5f71\u54cd\u529b\u7684\u671f\u520a\u548c\u6700\u65b0\u7684\u7814\u7a76\u6210\u679c\u6765\u4fdd\u8bc1\u6587\u732e\u7684\u6743\u5a01\u6027\u3002\u540c\u65f6\uff0c\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u65f6\uff0c\u52a1\u5fc5\u8fdb\u884c\u9a8c\u8bc1\u548c\u4ea4\u53c9\u68c0\u67e5\uff0c\u786e\u4fdd\u6240\u7528\u6570\u636e\u548c\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u9002\u5f53\u7684\u7edf\u8ba1\u65b9\u6cd5\u548c\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u589e\u5f3a\u7efc\u8ff0\u7684\u79d1\u5b66\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u5199\u6587\u732e\u7efc\u8ff0\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u52a8\u5316\u548c\u534a\u81ea\u52a8\u5316\u7684\u65b9\u5f0f\uff0c\u5229\u7528Python\u7684\u4e30\u5bcc\u5e93\u548c\u5de5\u5177\uff0c\u63d0\u9ad8\u6587\u732e\u6536\u96c6\u3001\u5904\u7406\u548c [&hellip;]","protected":false},"author":3,"featured_media":1183821,"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\/1183815"}],"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=1183815"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183815\/revisions"}],"predecessor-version":[{"id":1183824,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183815\/revisions\/1183824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1183821"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1183815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1183815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1183815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}