Skip to content

Commit 01abf57

Browse files
committed
1.根据股票代码给公司分类,包括:深A、沪A、深B、沪B、三板、其它、非上市;
2.修改格式错误的A股上市公司股票代码。
1 parent 43922ab commit 01abf57

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Graph/graph_init_create.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ def create_company(): # 在图中创建A股上市公司节点
3232
print(count, row)
3333

3434

35+
def create_industry(): # 在图中创建行业节点,以及公司与行业的关系
36+
with open('../Data/industry_tags.csv', 'r', encoding='utf-8', newline='') as csvfile:
37+
rows = csv.reader(csvfile)
38+
k = -1
39+
for row in rows:
40+
k += 1
41+
if k == 0:
42+
continue
43+
com_node = graph.find_one(label='COMPANY', property_key='stock_code', property_value=row[0])
44+
ind_node = graph.find_one(label='INDUSTRY', property_key='ind_name', property_value=row[2])
45+
if not com_node:
46+
# print(k, row)
47+
continue
48+
if ind_node:
49+
com_rel = Relationship(com_node, 'COM_BelongTo_I', ind_node)
50+
graph.create(com_rel)
51+
else:
52+
new_node = Node('INDUSTRY')
53+
new_node['ind_name'] = row[2]
54+
com_rel = Relationship(com_node, 'COM_BelongTo_I', new_node)
55+
graph.create(new_node | com_rel)
56+
print(k, row)
57+
58+
3559
def create_com_output(): # 在图中创建公司产业输出关系(上下游),如果公司节点不存在则创建
3660
file_path = '../Data/A股上市公司上下游/'
3761
files = file_name(file_path)
@@ -194,3 +218,6 @@ def create_com_invest(): # 在图中创建公司投资关系,如果公司节
194218

195219
if __name__ == '__main__':
196220
create_company()
221+
create_industry()
222+
create_com_output()
223+
create_com_invest()

0 commit comments

Comments
 (0)