|
楼主 |
发表于 2024-7-22 21:04:30
|
显示全部楼层
读取excel并创建节点
import pandas as pd
from py2neo import Graph, Node, Relationship,NodeMatcher
def readExcel(file_name,dropna_col = ''):
# 读取Excel文件
#df = pd.read_excel('abc.csv',sheet_name=0,header = 0)
df = pd.read_csv(file_name,header = 2)
if dropna_col != '':
df1 = df.dropna(subset = [dropna_col])
# 查看前几行数据
print(df1[['姓名','业绩名称']])
return df1
df = readExcel(file_name = 'abc.csv',dropna_col = '姓名');
db = Graph("bolt://localhost:7687", user="neo4j", password="gao6318866", name="neo4j") # 连接数据库
def create_node_from_df(df,db,label,attributes):
for index, row in df.iterrows():
name = row['姓名']
job_number = row['工号']
node = Node("教师");
for attr in attributes:
node[attr] = row[attr]
db.create(node)
create_node_from_df(df,db,label = '教师',attributes = ["姓名","工号"]) |
|