In [1]:
import numpy as np
import pandas as pd

In [2]:
data = pd.read_csv('Compendex Data/Engineering_Village_detailed_4-23-2017_8657315.csv')
country_list = list(np.loadtxt('country_list.txt',dtype=str,delimiter='\t'))

In [3]:
data['Author affiliation'][0]


Out[3]:
'(1) Institute of Microelectronics, Peking University, Beijing; 100871, China (2) Shenzhen Graduate School, Peking University, Shenzhen; 518055, China '

In [38]:
country_list[46]


Out[38]:
'China'

In [5]:
affiliation = data['Author affiliation']

In [6]:
len(affiliation)


Out[6]:
100

In [7]:
len(country_list)


Out[7]:
264

In [18]:
country_counts = (np.zeros((len(country_list),len(country_list))))

In [28]:
for institution in affiliation:
    for n in range(0,len(country_list)):
        for m in range(n,len(country_list)):
            if country_list[n] in institution:
                #print "found one country"
                if country_list[m] in institution:
                    #print "found a collaboration"
                    country_counts[n,m] += 1
                    
                else:
                    pass
            else:
                pass




In [39]:
country_counts[46]


Out[39]:
array([   0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,  176.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    5.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    5.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          5.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    5.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,   25.,    0.,    0.,
          0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,    0.,
          0.,    0.,    0.])

In [11]:
country_list[0]


Out[11]:
'Afghanistan'

In [24]:



Out[24]:
0.0

In [83]:



Out[83]:
-1

In [40]:
np.savetxt("country_counts_trial_firstdatafile.csv",country_counts,delimiter = ',')

In [ ]: