1. 程式人生 > >【資料分析】演算法+Echarts小練

【資料分析】演算法+Echarts小練

'''
處理邏輯:
按number去處理
先遍歷所有的number挨個去找有沒有在列表裡的,在列表裡的拿出另外一個append
把number去除的列表
'''
li = []
with open(r'F:\資料分析專用\通話圈分析\new\test1.txt', 'r') as f:
    lines = f.readlines()
    for line in lines:
        li.append(line.strip().split('\t'))

b = len(li)
for i in range(b):
    for j in range(b):
        x 
= list(set(li[i] + li[j])) y = len(li[j]) + len(li[i]) if i == j or li[i] == 0 or li[j] == 0: break elif len(x) < y: li[i] = x li[j] = [0] fin_li = ([i for i in li if i != [0]]) for i, v in enumerate(fin_li): with open(r'F:\資料分析專用\通話圈分析\file\%s.txt
' % i, 'a') as f: for v1 in v: f.write(v1+'\n')
通話圈整合
li = []
with open(r'F:\資料分析專用\通話圈分析\new\test1.txt', 'r') as f:
    lines = f.readlines()
    for line in lines:
        li.append(line.strip().split('\t'))
for i in range(45):
    with open(r'F:\資料分析專用\通話圈分析\file\%s.txt
'%i, 'r') as fb: with open(r'F:\資料分析專用\通話圈分析\group\%s.txt'%i,'w')as fp: lins = fb.readlines() for i in lins: # print(i.strip()) for ind in li: if i.strip() == ind[0]: # print(ind) fp.write(' '.join(ind)+'\n')
整合圈整合
'''
先生成nodes和links
'''
num = 0
while num <= 44:
    with open(r'F:\資料分析專用\通話圈分析\group\%s.txt' % num, 'r') as f:
        lines = f.readlines()
        nodes_name = []
        for line in lines:
            nodes_name.append(line.strip().split(' ')[0])
        nodes_nam = list(set(nodes_name))
        # print(nodes_name)
    nodes = []
    for i in nodes_nam:
        dic = {}
        dic['name'] = i
        dic['symbolSize'] = int(nodes_name.count(i)) * 2
        nodes.append(dic)
    # print(nodes)
    links = []
    links_path = []
    for line in lines:
        links_path.append(line.strip().split(' '))
    for li in links_path:
        dic_path = {}
        dic_path['source'] = li[0]
        dic_path['target'] = li[1]
        links.append(dic_path)

    from pyecharts import Graph

    graph = Graph("關係圖-環形引導佈局示例", width=1200, height=600)
    graph.add("", nodes, links, repulsion=80, graph_repulsion=20, graph_edge_length=350,
              line_curve=0.1, label_text_color=None, line_width=1.5, )

    graph.render(r'F:\資料分析專用\通話圈分析\img\%s.html' % num)

    num += 1
Echarts