构建金融知识图谱
from sklearn import metrics
import tushare as ts
from sklearn.cluster import KMeans
import numpy
import collections
import pandas
from sklearn import metrics
import pandas as pd
import time
from multiprocessing import Pool
from py2neo import Graph,Node,Relationship
##连接neo4j数据库,输入地址、用户名、密码
graph = Graph('http://localhost:7474',username='neo4j',password='08300734')
#获取连接备用
cons = ts.get_apis()
pro = ts.pro_api()
pp=pro.daily_basic(ts_code='', trade_date='20181105')
code=list(pp['ts_code'])
ccpt = pro.concept()
df = pro.concept_detail(id='TS2', fields='ts_code,name')
data = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')
data1=data[['ts_code','name']]
test_node_2 = Node(label='ru_yi_zhuan',name='皇帝')
data2=data1.values
for m in ccpt[['code','name']].values[:100]:
fd1=m[0]
pd1=m[1]
dfd = pro.concept_detail(id=fd1, fields='ts_code,name')
dfd1=dfd.values
ctt=Node(label='concept',name=pd1)
graph.create(ctt)
for tt in dfd1:
fdd=tt[1]
sk = Node(label='stock',name=fdd)
node_munv_node = Relationship(sk,'belong_to_concept',ctt)
graph.create(sk)
graph.create(node_munv_node)
print(fdd,pd1)
建立股票node 和概念node ,并且指定关系