Ad statistics, ranking of the top ten countries in the annual paper statistics

Source: Internet
Author: User

1. Get the number of papers in each country, the method is to write a good SQL statement, directly with the SQL statement statistics, it may be slower, the other way is to pass the ID all over the local statistics.

ImportPymysqlImportJSONImportReImportCollectionsImportJSONdefget_article_from_mysql (SQL): Conn=Pymysql.connect (Host='localhost', Port= 3306, the user='Root', passwd="', DB='python',) cursor=conn.cursor () a=cursor.execute (SQL) b=Cursor.fetchmany (a)returnB[0][0]defgetsqllist (): Country= ['USA',' China','UK','Germany','Italy','Japan','Canada','France','Spain','Australia'] Top_country= []     forIinchCountry:top_country.append ('%'+i+'%') Year= []     forIinchRange (1995,2017): Year.append (str (i))PrintYear str1='SELECT COUNT (*) from Alzheimer where Authorinfor like'str2='&& union_kwd_str! = \ ' \ ' && pub_year ='countrydict= {}     forIinchtop_country:sqllist= []         forJinchYear:sql= str1+"'"+i+"'"+str2+"'"+j+"'"sqllist.append (SQL) countrydict[i]=sqllistreturncountrydictdefchange_with_year (): Countrydict=getsqllist () fobj= Open ('1203_topcountry_article_change_with_year.json','W') Countrylist= ['USA',' China','UK','Germany','Italy','Japan','Canada','France','Spain','Australia']     forCountryinchcountrylist:this_country_sql_list= countrydict['%'+country+'%'] This_year_article_num= []         forSqlinchthis_country_sql_list:this_year_article_num.append (Get_article_from_mysql (SQL)) data= {            'name': Country,'type':' Line',            'Stack':' Total',            'Areastyle':'{normal: {}}',            'Data': This_year_article_num}PrintCountry,this_year_article_num Json_data=json.dumps (data) fobj.write (json_data) fobj.write (',') Fobj.write ('\ n')#change_with_year ()defarticle_each_year (): str1='SELECT COUNT (*) from Alzheimer where union_kwd_str! = \ ' \ ' && pub_year ='All_this_year_article_num= []     forIinchRange (1996,2017): year=STR (i) SQL= str1+"'"+year+"'"all_this_year_article_num.append (Get_article_from_mysql (SQL)) data= {        'Article_each_year': All_this_year_article_num} fobj= Open ('1204_article_each_year_num.json','W') Json_data=json.dumps (data) fobj.write (json_data)Printall_this_year_article_numarticle_each_year ()

2) Obtain the annual paper information of each country and seek the proportion. For example, 1996 U.S. ratio = 1996 U.S. paper Volume/1996 paper Volume worldwide

 from __future__ ImportDivisionImportJsoncountry= ['USA',' China','UK','Germany','Italy','Japan','Canada','France','Spain','Australia'] L= [    [1, 0, 15, 10, 19, 23, 32, 26, 49, 93, 161, 348, 669, 1471, 1669, 1892, 2128, 2762, 3090, 2675, 1458], [0, 0, 0, 0, 0,2, 1, 1, 5, 14, 12, 19, 29, 78, 111, 144, 351, 517, 737, 1062, 899],    [ 2, 2, 1, 3, 14, 11, 10, 20, 26, 34, 45, 72, 127, 204, 265, 308, 428, 570, 697, 723, 597], [0,3, 4, 7, 8, 11, 9, 8, 27, 24, 21, 33, 67, 98, 124, 149, 253, 303, 370, 358, 318], [0,1, 5, 5, 3, 7, 3, 10, 12, 27, 22, 28, 44, 67, 94, 106, 187, 285, 330, 322, 280],    [ 1, 3, 4, 8, 7, 10, 13, 10, 11, 18, 26, 30, 30, 61, 85, 120, 189, 256, 295, 291, 199], [0,5, 7, 2, 4, 2, 6, 10, 13, 18, 21, 32, 34, 69, 96, 112, 197, 286, 340, 340, 251], [0,4, 2, 6, 7, 5, 9, 10, 13, 12, 17, 17, 29, 44, 65, 63, 126, 155, 189, 209, 184], [0, 0,1, 2, 1, 6, 2, 0, 5, 7, 9, 18, 14, 46, 57, 72, 111, 146, 252, 198, 173], [0, 0,1, 0, 0, 1, 2, 3, 4, 13, 11, 14, 22, 45, 53, 74, 120, 162, 245, 195, 169]    ]PrintLen (l[0]) percent_dict={} forIinchRange (10): Percent_dict[i]=[]year= [1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016]ltotal= [19, 54, 63, 84, 106, 127, 134, 171, 293, 504, 695, 1306, 2325, 4566, 5415, 5859, 7537, 9603, 11349, 10850, 7211]#For i in range (len (l[0])):#ltotal_i = 0#For J in range:#ltotal_i + = L[j][i]#ltotal.append (ltotal_i) forIinchRange (len (l[0)): forJinchRange (10): Percent_dict[j].append (Round (L[j][i]/ltotal[i],2))     PrintPercent_dictfobj= Open ('1204_top10country_article.json','W') forIinchRange (10): Data= {            'name': Country[i],'type':' Line',            'Stack':' Total',            'Areastyle':'{normal: {}}',            'Data':p Ercent_dict[i]} json_data=json.dumps (data) fobj.write (json_data) fobj.write (',') Fobj.write ('\ n')

Ad statistics, ranking of the top ten countries in the annual paper statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.