[weighted-degree]annual_genre.py
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#-*-encoding utf-8 -*-
import matplotlib.pyplot as plt
import networkx as nx
from openpyxl import load_workbook
movie_genre_list = []
movie_audience_list = []
movie_edge_list = []
movie_graph_list = []
movie_check_list = []
max_audience=-1
load_wb = load_workbook("Movie_data/movie_top500.xlsx", data_only=True)
load_ws = load_wb['Sheet1']
def make_edge(movielist):
edge_list = []
for i in range(0,len(movielist)):
for j in range(0, len(movielist)):
if i == j:
break
else:
edge_list.append((movielist[i],movielist[j]))
return edge_list
movie_year=input("영화의 개봉연도 4자리를 입력해주세요: ")
range_count=0
for i in range(7,507,1):
movie_year_check=str(load_ws['C'+str(i)].value)
distributor_name='L'+str(i)
genre_name='M'+str(i)
if movie_year == movie_year_check[:4]:
name3=(str(load_ws[distributor_name].value) +','+ str(load_ws[genre_name].value)).split(',')
movie_audience_list.append(int(load_ws['F'+str(i)].value))
movie_genre_list.append(name3)
range_count+=1
for i in range(0, range_count):
if movie_genre_list[i] in movie_check_list:
movie_audience_list[i]=movie_audience_list[i]+movie_audience_list[movie_check_list.index(movie_genre_list[i])]
movie_audience_list[movie_check_list.index(movie_genre_list[i])]=movie_audience_list[i]
movie_check_list.append(movie_genre_list[i])
else:
movie_check_list.append(movie_genre_list[i])
if movie_audience_list[i] > max_audience:
max_audience=movie_audience_list[i]
for i in range(0, range_count):
movie_graph = nx.Graph()
movie_edge = make_edge(movie_genre_list[i])
movie_edge_list.append(movie_edge)
movie_graph.add_nodes_from(movie_genre_list[i])
movie_graph.add_edges_from(movie_edge_list[i], weight = movie_audience_list[i]/(max_audience+1))
movie_graph_list.append(movie_graph)
movie_total = nx.Graph()
for i in range(0,range_count):
movie_total = nx.compose(movie_total, movie_graph_list[i])
degree = movie_total.degree()
nx.write_gexf(movie_total, "Gephi/[weighted-degree]annual_genre_"+movie_year+".gexf")
plt.figure(figsize=(20,20))
pos = nx.spring_layout(movie_total, iterations = 10)
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)
plt.show()