I've developed a program that stores a list of ids, so
Butforthedesiredpurposes,thedatashouldtakethesequentialform,sothatthefirstpairofidsissomethinglike:"889926212541448192" becomes 1 and "889919950248448000" becomes 2. That is, the file to get should be something like:
Wherethefirstidconnectswith2,3and6,andtheid4onlywith5,forminganetwork.
Ihavenoexperienceinthisarea,butIcannotfindawaytodothisreading.
Itriedtodosomeprograms,buttheyreadonlyrowandnotcolumnidtoid.Thisdataissavedfollowingthefollowingprogram
importjson
arq=open('ids.csv','w')arq.write('Source'+','+'Target')arq.write("\ n")
list_rede = [] #list to save all ids
with open ('data_twitter.json', 'r') as f:
for line in f:
lista = []
tweet = json.loads(line) # reescreve como um dicionário Python
lista = list(tweet.keys()) #escreve lista das chaves
try:
if 'retweeted_status' in lista:
id_rt = json.dumps(tweet['retweeted_status']['id_str'])
id_status = json.dumps(tweet['id_str'])
lista_rede.append(tweet['id_str'])
lista_rede.append(tweet['retweeted_status']['id_str'])
arq.write( id_status +','+ id_rt )
arq.write("\n")
if tweet['quoted_status'] in lista :
id_rt = json.dumps(tweet['quoted_status']['id_str'])
id_status = json.dumps(tweet['id_str'])
lista_rede.append(tweet['id_str'])
lista_rede.append(tweet['quoted_status']['id_str'])
arq.write( id_status +','+ id_rt )
arq.write("\n")
except:
continue
arq.close ()
As a result I have a file with ids data in pairs of interactions
How can I then rearrange this data in reading, or even how to write them ?? In python or another language?