PYTHON::知识图谱

仅当作记录

import py2neo
from py2neo import Graph,Node,Relationship
import pandas as pd

graph = Graph("http://localhost:7474")

graph = Graph("http://localhost:7474",uername="neo4j",password="lh990816")

graph.delete_all()#清空所有内容

data = pd.read_excel("D:/data.xlsx")
print(data.shape)
datalable = list(data)
data_row = len(data)
print(data_row)

# print(data.columns[1])
# b = Node(‘Person‘,name=‘yingying‘)
# graph.create(b)

datalable2 = len(datalable)
print(datalable2)
for i in range(0,data_row):
    print(data.loc[i][datalable[1]])
    Nodee = Node(‘impentity‘,name = str(data.loc[i][datalable[1]]))
    graph.create(Nodee)
    for j in range(2,datalable2):
        print(data.loc[i][j])
        print(data.columns[j])
        # if(data.loc[i][j]==data.loc[i-1][j]):
        #     selector = py2neo.matching.NodeMatcher(graph)
        #     ndoe = selector.match(‘entity‘).where(‘_.name = "data.loc[i][j]"‘).first()
        # else:
        node = Node(‘entity‘,name = str(data.loc[i][j]))
        graph.create(node)
        graph.create(Relationship(Nodee,data.columns[j],node))
#print(data.head())

相关推荐