김한준

Delete movie.py

1 -#-*-encoding utf-8 -*-
2 -
3 -import matplotlib.pyplot as plt
4 -import networkx as nx
5 -from openpyxl import load_workbook
6 -
7 -load_wb = load_workbook("movie_top500.xlsx", data_only=True)
8 -load_ws = load_wb['Sheet1']
9 -
10 -
11 -def make_edge(movielist):
12 - edge_list = []
13 - for i in range(0,len(movielist)):
14 - for j in range(0, len(movielist)):
15 - if i == j:
16 - break
17 - else:
18 - edge_list.append((movielist[i],movielist[j]))
19 - return edge_list
20 -
21 -movie_director_list = []
22 -movie_audience_list = []
23 -
24 -for i in range(7,507,1):
25 - distributor_name='L'+str(i)
26 - director_name='K'+str(i)
27 - name3=(str(load_ws[distributor_name].value) +','+ str(load_ws[director_name].value)).split(',')
28 - movie_audience_list.append(int(load_ws['F'+str(i)].value))
29 - movie_director_list.append(name3)
30 -
31 -
32 -movie_edge_list = []
33 -movie_graph_list = []
34 -movie_check_list = []
35 -
36 -for i in range(0, 500):
37 - movie_graph = nx.Graph()
38 - movie_edge = make_edge(movie_director_list[i])
39 - if movie_director_list[i] in movie_check_list:
40 - movie_audience_list[i]=movie_audience_list[i]+movie_audience_list[movie_check_list.index(movie_director_list[i])]
41 - movie_audience_list[movie_check_list.index(movie_director_list[i])]=movie_audience_list[i]
42 - movie_check_list.append(movie_director_list[i])
43 - else:
44 - movie_check_list.append(movie_director_list[i])
45 -
46 - movie_edge_list.append(movie_edge)
47 - movie_graph.add_nodes_from(movie_director_list[i])
48 - movie_graph.add_edges_from(movie_edge_list[i], weight = round(movie_audience_list[i]/100000000,5))
49 - movie_graph_list.append(movie_graph)
50 -
51 -
52 -movie_total = nx.Graph()
53 -
54 -for i in range(0,500):
55 - movie_total = nx.compose(movie_total, movie_graph_list[i])
56 -
57 -degree = movie_total.degree()
58 -nx.write_gexf(movie_total, "movie.gexf")
59 -
60 -
61 -plt.figure(figsize=(20,20))
62 -pos = nx.spring_layout(movie_total, iterations = 10)
63 -nx.draw(movie_total, pos, alpha = 1, line_color= 'black', linewidths = 0, width = 0.05 ,node_size = 100, node_color = 'w', with_labels = True, font_family='NanumGothic', font_color='black', font_size=8)
64 -plt.show()
65 -
66 -