![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
''' 处理逻辑: 按number去处理 先遍历所有的number挨个去找有没有在列表里的,在列表里的拿出另外一个append 把number去除的列表 ''' li = [] with open(r'F:数据分析专用通话圈分析 ew est1.txt', 'r') as f: lines = f.readlines() for line in lines: li.append(line.strip().split(' ')) 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+' ')
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
li = [] with open(r'F:数据分析专用通话圈分析 ew est1.txt', 'r') as f: lines = f.readlines() for line in lines: li.append(line.strip().split(' ')) 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)+' ')
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
''' 先生成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