關於alzheimer disease論文的統計

來源:互聯網
上載者:User

標籤:app   append   pre   res   python   from   use   sql   country   

1.擷取2016年的所有關鍵字,儲存到keyword_2016.json中

import pymysqlimport jsonconn= pymysql.connect(        host=‘localhost‘,        port = 3306,        user=‘root‘,        passwd=‘‘,        db =‘python‘,        )cursor = conn.cursor()sql = "SELECT union_kwd_str,pmc_id FROM alzheimer where pub_year = ‘2016‘ && union_kwd_str != ‘‘ "a = cursor.execute(sql)print ab = cursor.fetchmany(a)  #b has 7887 abstract listabstract_list = []pmc_id_dict= {}for j in range(a):    abstract_list.append(b[j][0])    pmc_id_dict[j] = b[j][1]def output_to_json(data,filename):    with open(filename,‘w‘) as file:        file.write(json.dumps(data))        file.close()    return json.dumps(data)output_data = {        ‘pub_year‘: "2016",        ‘count‘: a,        ‘keyword‘: abstract_list    }output_to_json(output_data, ‘keyword_2016.json‘)

從keyword_2016。json中讀取關鍵詞,並統計選出前25的關鍵詞

import re  import collections  import jsondef input_from_json(filename):    with open(filename,‘r‘) as file:        data = json.loads(file.read())        file.close()        return datadef count_word(path):      result = {}    keyword_list = input_from_json(path)[‘keyword‘]      for all_the_text in keyword_list:        for word in all_the_text.split(‘,‘):             if word not in result:                  result[word] = 0              result[word] += 1                     return result         def sort_by_count(d):      d = collections.OrderedDict(sorted(d.items(), key = lambda t: -t[1]))      return d   if __name__ == ‘__main__‘:      file_name = "keyword_2016.json"      fobj2 = open(‘sort_keyword_2016.json‘,‘w‘)     dword = count_word(file_name)      dword = sort_by_count(dword)            jsonlist = []    num = 0    for key,value in dword.items():        num += 1        key = re.sub("_", " ", key)        data = {        ‘name‘: key,        ‘value‘: value        }        json_data = json.dumps(data)        if num < 25:            fobj2.write(json_data)            fobj2.write(‘,‘)        if num == 25:            fobj2.write(json_data)        

  

2.擷取發表論文量排名前十的國家

1)把所有第一作者的資訊儲存到authorinfor.json中

import pymysqlimport jsonconn= pymysql.connect(        host=‘localhost‘,        port = 3306,        user=‘root‘,        passwd=‘‘,        db =‘python‘,        )cursor = conn.cursor()sql = "SELECT authorinfor,pmc_id FROM alzheimer WHERE authorinfor != ‘‘"a = cursor.execute(sql)print ab = cursor.fetchmany(a)  #b has 7887 abstract listauthorinfor_list = []pmc_id_dict= {}for j in range(a):    authorinfor_list.append(b[j][0])    pmc_id_dict[j] = b[j][1]def output_to_json(data,filename):    with open(filename,‘w‘) as file:        file.write(json.dumps(data))        file.close()    return json.dumps(data)output_data = {        ‘pub_year‘: "2016",        ‘count‘: a,        ‘authorinfor‘: authorinfor_list,        ‘pmc_id‘: pmc_id_dict    }output_to_json(output_data, ‘authorinfor.json‘)

2)選出排名前十的國家

import re  import collections  import jsondef input_from_json(filename):    with open(filename,‘r‘) as file:        data = json.loads(file.read())        file.close()        return datadef count_word(path):      result = {}    authorinfor_list = input_from_json(path)[‘authorinfor‘]      for all_the_text in authorinfor_list:        country = all_the_text.split(‘,‘)[-1]        country = re.sub("\.","",country)        country = re.sub("\\n","",country)        country = country.encode(‘utf-8‘)        if country not in result:            result[country] = 0        result[country] += 1                    return result        def sort_by_count(d):      d = collections.OrderedDict(sorted(d.items(), key = lambda t: -t[1]))      return d   if __name__ == ‘__main__‘:      file_name = "authorinfor.json"      fobj2 = open(‘sort_country.json‘,‘w‘)     dword = count_word(file_name)      dword = sort_by_count(dword)            jsonlist = []    num = 0    for country,value in dword.items():        num += 1        data = {        ‘name‘: country,        ‘value‘: value        }        json_data = json.dumps(data)        if num < 50:            fobj2.write(json_data)            fobj2.write(‘\n‘)    countrylist = dword.keys()    valuelist = dword.values()    print countrylist[:11]    print valuelist[:11]

 

關於alzheimer disease論文的統計

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.