Loading...
image
hxy

我们可以卸载2020重新安装吗?这个版本是有病毒的

平台数据导出数据处理方法

hxy    2018-11-19 20:51

目前,实验室平台提供用户关注关系API,导出数据格式为Json,为了方便大家在算法中使用,特此提供数据处理参考(页面停止维护,新版本请移驾:http://neusncp.com/api/)。

格式:Json数据格式

在Python语言处理下提供一种数据处理方式,以NetworkX为例,代码如下:

def load_json_data(path,attrs):
    '''
    : Load data from Json file.
    :param path: 
    :return: 
    '''
    G = nx.Graph()
    f = open(path, encoding='utf-8')
    data = json.load(f)

    nodes = data['nodes']
    links = data['links']

    print(nodes)
    print(links)

    for n in nodes:
        G.add_node(n['id'])
        for a in attrs:
            G.node[n['id']][a] = n[a]

    for e in links:
        G.add_edge(e['source'], e['target'])

    return G

页面调用示例:#test.py

# 给出json路径
path1 = '../data/data-2017xxxxxxx.json'
# 给出Json数据中包含的属性列表
attrs1=['age','birthdate','email','gender', 'id', 'img', 'name','signature','username']
G1 = load_json_data(path1, attrs1)
Fig 1. Initial friendships of registered users on NEUSNCP.

 

Fig 2.  following relationship of NEUSNCP social network on 26th, Aug, 2019.
Last Modified: 2019-08-26 16:26
Views: 532

[[total]] comments

Post your comment
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]Floor
  2. Click to load more...
  3. Post your comment